index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
  4. <el-form-item label="字典标签" prop="dictLabel">
  5. <el-input
  6. v-model="queryParams.dictLabel"
  7. placeholder="请输入字典标签"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="状态" prop="status">
  14. <el-select v-model="queryParams.status" placeholder="数据状态" clearable size="small">
  15. <el-option
  16. v-for="dict in statusOptions"
  17. :key="dict.dictValue"
  18. :label="dict.dictLabel"
  19. :value="dict.dictValue"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-row :gutter="10" class="mb8">
  29. <el-col :span="1.5">
  30. <el-button
  31. type="primary"
  32. plain
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. v-hasPermi="['system:dict:add']"
  37. >新增</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="success"
  42. plain
  43. icon="el-icon-edit"
  44. size="mini"
  45. :disabled="single"
  46. @click="handleUpdate"
  47. v-hasPermi="['system:dict:edit']"
  48. >修改</el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button
  52. type="danger"
  53. plain
  54. icon="el-icon-delete"
  55. size="mini"
  56. :disabled="multiple"
  57. @click="handleDelete"
  58. v-hasPermi="['system:dict:remove']"
  59. >删除</el-button>
  60. </el-col>
  61. <el-col :span="1.5">
  62. <el-button
  63. type="warning"
  64. plain
  65. icon="el-icon-download"
  66. size="mini"
  67. @click="handleExport"
  68. v-hasPermi="['system:dict:export']"
  69. >导出</el-button>
  70. </el-col>
  71. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  72. </el-row>
  73. <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
  74. <el-table-column type="selection" width="55" align="center" />
  75. <el-table-column label="字典编码" align="center" prop="id" />
  76. <el-table-column label="字典标签" align="center" prop="dictLabel" />
  77. <el-table-column label="字典键值" align="center" prop="dictValue" />
  78. <el-table-column label="字典排序" align="center" prop="dictSort" />
  79. <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
  80. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  81. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  82. <template slot-scope="scope">
  83. <span>{{ parseTime(scope.row.createTime) }}</span>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  87. <template slot-scope="scope">
  88. <el-button
  89. size="mini"
  90. type="text"
  91. icon="el-icon-edit"
  92. @click="handleUpdate(scope.row)"
  93. v-hasPermi="['system:dict:edit']"
  94. >修改</el-button>
  95. <el-button
  96. size="mini"
  97. type="text"
  98. icon="el-icon-delete"
  99. @click="handleDelete(scope.row)"
  100. v-hasPermi="['system:dict:remove']"
  101. >删除</el-button>
  102. </template>
  103. </el-table-column>
  104. </el-table>
  105. <pagination
  106. v-show="total>0"
  107. :total="total"
  108. :page.sync="queryParams.pageNum"
  109. :limit.sync="queryParams.pageSize"
  110. @pagination="getList"
  111. />
  112. <!-- 添加或修改参数配置对话框 -->
  113. <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
  114. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  115. <el-form-item label="字典类型">
  116. <el-input v-model="form.dictType" :disabled="true" />
  117. </el-form-item>
  118. <el-form-item label="数据标签" prop="dictLabel">
  119. <el-input v-model="form.dictLabel" placeholder="请输入数据标签" />
  120. </el-form-item>
  121. <el-form-item label="数据键值" prop="dictValue">
  122. <el-input v-model="form.dictValue" placeholder="请输入数据键值" />
  123. </el-form-item>
  124. <el-form-item label="显示排序" prop="dictSort">
  125. <el-input-number v-model="form.dictSort" controls-position="right" :min="0" />
  126. </el-form-item>
  127. <el-form-item label="状态" prop="status">
  128. <el-radio-group v-model="form.status">
  129. <el-radio
  130. v-for="dict in statusOptions"
  131. :key="dict.dictValue"
  132. :label="dict.dictValue"
  133. >{{dict.dictLabel}}</el-radio>
  134. </el-radio-group>
  135. </el-form-item>
  136. <el-form-item label="备注" prop="remark">
  137. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  138. </el-form-item>
  139. </el-form>
  140. <div slot="footer" class="dialog-footer">
  141. <el-button type="primary" @click="submitForm">确 定</el-button>
  142. <el-button @click="cancel">取 消</el-button>
  143. </div>
  144. </el-dialog>
  145. </div>
  146. </template>
  147. <script>
  148. import { listData, getData, delData, addData, updateData } from "@/api/system/dict/menuDict";
  149. import { listType } from "@/api/system/dict/type";
  150. export default {
  151. name: "Data",
  152. data() {
  153. return {
  154. // 遮罩层
  155. loading: true,
  156. // 选中数组
  157. ids: [],
  158. // 非单个禁用
  159. single: true,
  160. // 非多个禁用
  161. multiple: true,
  162. // 显示搜索条件
  163. showSearch: true,
  164. // 总条数
  165. total: 0,
  166. // 字典表格数据
  167. dataList: [],
  168. // 默认字典类型
  169. defaultDictType: "",
  170. // 弹出层标题
  171. title: "",
  172. // 是否显示弹出层
  173. open: false,
  174. // 状态数据字典
  175. statusOptions: [],
  176. // 查询参数
  177. queryParams: {
  178. pageNum: 1,
  179. pageSize: 10,
  180. dictName: undefined,
  181. dictType: "sys_common_status",
  182. status: undefined
  183. },
  184. // 表单参数
  185. form: {},
  186. // 表单校验
  187. rules: {
  188. dictLabel: [
  189. { required: true, message: "数据标签不能为空", trigger: "blur" }
  190. ],
  191. dictValue: [
  192. { required: true, message: "数据键值不能为空", trigger: "blur" }
  193. ],
  194. dictSort: [
  195. { required: true, message: "数据顺序不能为空", trigger: "blur" }
  196. ]
  197. }
  198. };
  199. },
  200. created() {
  201. const dictId = this.$route.params && this.$route.params.dictId;
  202. this.getDicts("sys_normal_disable").then(response => {
  203. this.statusOptions = response.data;
  204. });
  205. this.getList();
  206. },
  207. methods: {
  208. /** 查询字典数据列表 */
  209. getList() {
  210. this.loading = true;
  211. listData(this.queryParams).then(response => {
  212. this.dataList = response.rows;
  213. this.total = response.total;
  214. this.loading = false;
  215. });
  216. },
  217. // 数据状态字典翻译
  218. statusFormat(row, column) {
  219. return this.selectDictLabel(this.statusOptions, row.status);
  220. },
  221. // 取消按钮
  222. cancel() {
  223. this.open = false;
  224. this.reset();
  225. },
  226. // 表单重置
  227. reset() {
  228. this.form = {
  229. id: undefined,
  230. dictLabel: undefined,
  231. dictValue: undefined,
  232. dictSort: 0,
  233. status: "0",
  234. remark: undefined
  235. };
  236. this.resetForm("form");
  237. },
  238. /** 搜索按钮操作 */
  239. handleQuery() {
  240. this.queryParams.pageNum = 1;
  241. this.getList();
  242. },
  243. /** 重置按钮操作 */
  244. resetQuery() {
  245. this.resetForm("queryForm");
  246. this.handleQuery();
  247. },
  248. /** 新增按钮操作 */
  249. handleAdd() {
  250. this.reset();
  251. this.open = true;
  252. this.title = "添加字典数据";
  253. this.form.dictType = this.queryParams.dictType;
  254. },
  255. // 多选框选中数据
  256. handleSelectionChange(selection) {
  257. this.ids = selection.map(item => item.id)
  258. this.single = selection.length!=1
  259. this.multiple = !selection.length
  260. },
  261. /** 修改按钮操作 */
  262. handleUpdate(row) {
  263. this.reset();
  264. const id = row.id || this.ids
  265. getData(id).then(response => {
  266. this.form = response.data;
  267. this.open = true;
  268. this.title = "修改字典数据";
  269. });
  270. },
  271. /** 提交按钮 */
  272. submitForm: function() {
  273. this.$refs["form"].validate(valid => {
  274. if (valid) {
  275. if (this.form.id != undefined) {
  276. updateData(this.form).then(response => {
  277. this.msgSuccess("修改成功");
  278. this.open = false;
  279. this.getList();
  280. });
  281. } else {
  282. addData(this.form).then(response => {
  283. this.msgSuccess("新增成功");
  284. this.open = false;
  285. this.getList();
  286. });
  287. }
  288. }
  289. });
  290. },
  291. /** 删除按钮操作 */
  292. handleDelete(row) {
  293. const ids = row.id || this.ids;
  294. this.$confirm('是否确认删除字典编码为"' + ids + '"的数据项?', "警告", {
  295. confirmButtonText: "确定",
  296. cancelButtonText: "取消",
  297. type: "warning"
  298. }).then(function() {
  299. return delData(ids);
  300. }).then(() => {
  301. this.getList();
  302. this.msgSuccess("删除成功");
  303. })
  304. },
  305. /** 导出按钮操作 */
  306. handleExport() {
  307. this.download('system/dict/data/export', {
  308. ...this.queryParams
  309. }, `data_${new Date().getTime()}.xlsx`)
  310. }
  311. }
  312. };
  313. </script>
  314. <strong></strong>