data.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="字典名称" prop="dictType">
  5. <el-select v-model="queryParams.dictType">
  6. <el-option
  7. v-for="item in typeOptions"
  8. :key="item.dictId"
  9. :label="item.dictName"
  10. :value="item.dictType"
  11. />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="字典标签" prop="dictLabel">
  15. <el-input
  16. v-model="queryParams.dictLabel"
  17. placeholder="请输入字典标签"
  18. clearable
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="状态" prop="status">
  23. <el-select v-model="queryParams.status" placeholder="数据状态" clearable>
  24. <el-option
  25. v-for="dict in dict.type.sys_normal_disable"
  26. :key="dict.value"
  27. :label="dict.label"
  28. :value="dict.value"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  34. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  35. </el-form-item>
  36. </el-form>
  37. <el-row :gutter="10" class="mb8">
  38. <el-col :span="1.5">
  39. <el-button
  40. type="primary"
  41. plain
  42. icon="el-icon-plus"
  43. size="mini"
  44. @click="handleAdd"
  45. v-hasPermi="['system:dict:add']"
  46. >新增</el-button>
  47. </el-col>
  48. <!-- <el-col :span="1.5">
  49. <el-button
  50. type="success"
  51. plain
  52. icon="el-icon-edit"
  53. size="mini"
  54. :disabled="single"
  55. @click="handleUpdate"
  56. v-hasPermi="['system:dict:edit']"
  57. >修改</el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="danger"
  62. plain
  63. icon="el-icon-delete"
  64. size="mini"
  65. :disabled="multiple"
  66. @click="handleDelete"
  67. v-hasPermi="['system:dict:remove']"
  68. >删除</el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="warning"
  73. plain
  74. icon="el-icon-download"
  75. size="mini"
  76. @click="handleExport"
  77. v-hasPermi="['system:dict:export']"
  78. >导出</el-button>
  79. </el-col> -->
  80. <el-col :span="1.5">
  81. <el-button
  82. type="warning"
  83. plain
  84. icon="el-icon-close"
  85. size="mini"
  86. @click="handleClose"
  87. >关闭</el-button>
  88. </el-col>
  89. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  90. </el-row>
  91. <el-table
  92. border
  93. height="700"
  94. size="small"
  95. v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
  96. <!-- <el-table-column type="selection" width="55" align="center" /> -->
  97. <el-table-column label="字典编码" align="center" prop="dictCode" />
  98. <el-table-column label="字典标签" align="center" prop="dictLabel">
  99. <template slot-scope="scope">
  100. <span v-if="scope.row.listClass == '' || scope.row.listClass == 'default'">{{scope.row.dictLabel}}</span>
  101. <el-tag v-else :type="scope.row.listClass == 'primary' ? '' : scope.row.listClass">{{scope.row.dictLabel}}</el-tag>
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="字典键值" align="center" prop="dictValue" />
  105. <el-table-column label="字典排序" align="center" prop="dictSort" />
  106. <el-table-column label="状态" align="center" prop="status">
  107. <template slot-scope="scope">
  108. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
  109. </template>
  110. </el-table-column>
  111. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  112. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  113. <template slot-scope="scope">
  114. <span>{{ parseTime(scope.row.createTime) }}</span>
  115. </template>
  116. </el-table-column>
  117. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  118. <template slot-scope="scope">
  119. <el-button
  120. size="mini"
  121. type="text"
  122. icon="el-icon-edit"
  123. @click="handleUpdate(scope.row)"
  124. v-hasPermi="['system:dict:edit']"
  125. >编辑</el-button>
  126. <el-button
  127. size="mini"
  128. type="text"
  129. icon="el-icon-delete"
  130. @click="handleDelete(scope.row)"
  131. v-hasPermi="['system:dict:remove']"
  132. >删除</el-button>
  133. </template>
  134. </el-table-column>
  135. </el-table>
  136. <pagination
  137. v-show="total>0"
  138. :total="total"
  139. :page.sync="queryParams.pageNum"
  140. :limit.sync="queryParams.pageSize"
  141. @pagination="getList"
  142. />
  143. <!-- 添加或修改参数配置对话框 -->
  144. <DialogCom :title="title" :visible.sync="open" width="700px" append-to-body>
  145. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  146. <el-row>
  147. <el-col :span="12">
  148. <el-form-item label="字典类型">
  149. <el-input v-model="form.dictType" :disabled="true" />
  150. </el-form-item>
  151. </el-col>
  152. <el-col :span="12">
  153. <el-form-item label="数据标签" prop="dictLabel">
  154. <el-input v-model="form.dictLabel" placeholder="请输入数据标签" />
  155. </el-form-item>
  156. </el-col>
  157. </el-row>
  158. <el-row>
  159. <el-col :span="12">
  160. <el-form-item label="数据键值" prop="dictValue">
  161. <el-input v-model="form.dictValue" placeholder="请输入数据键值" />
  162. </el-form-item>
  163. </el-col>
  164. <el-col :span="12">
  165. <el-form-item label="样式属性" prop="cssClass">
  166. <el-input v-model="form.cssClass" placeholder="请输入样式属性" />
  167. </el-form-item>
  168. </el-col>
  169. </el-row>
  170. <el-row>
  171. <el-col :span="12">
  172. <el-form-item label="显示排序" prop="dictSort">
  173. <el-input-number
  174. style="width: 100%;"
  175. v-model="form.dictSort" controls-position="right" :min="0" />
  176. </el-form-item>
  177. </el-col>
  178. <el-col :span="12">
  179. <el-form-item label="回显样式" prop="listClass">
  180. <el-select
  181. style="width: 100%;"
  182. v-model="form.listClass">
  183. <el-option
  184. v-for="item in listClassOptions"
  185. :key="item.value"
  186. :label="item.label + '(' + item.value + ')'"
  187. :value="item.value"
  188. ></el-option>
  189. </el-select>
  190. </el-form-item>
  191. </el-col>
  192. </el-row>
  193. <el-row>
  194. <el-col :span="12">
  195. <el-form-item label="状态" prop="status">
  196. <el-radio-group v-model="form.status">
  197. <el-radio
  198. v-for="dict in dict.type.sys_normal_disable"
  199. :key="dict.value"
  200. :label="dict.value"
  201. >{{dict.label}}</el-radio>
  202. </el-radio-group>
  203. </el-form-item>
  204. </el-col>
  205. </el-row>
  206. <el-form-item label="备注" prop="remark">
  207. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  208. </el-form-item>
  209. </el-form>
  210. <div slot="footer" class="dialog-footer">
  211. <el-button type="primary" @click="submitForm">确 定</el-button>
  212. <el-button @click="cancel">取 消</el-button>
  213. </div>
  214. </DialogCom>
  215. </div>
  216. </template>
  217. <script>
  218. import { listData, getData, delData, addData, updateData } from "@/api/system/dict/data";
  219. import { optionselect as getDictOptionselect, getType } from "@/api/system/dict/type";
  220. export default {
  221. name: "Data",
  222. dicts: ['sys_normal_disable'],
  223. data() {
  224. return {
  225. // 遮罩层
  226. loading: true,
  227. // 选中数组
  228. ids: [],
  229. // 非单个禁用
  230. single: true,
  231. // 非多个禁用
  232. multiple: true,
  233. // 显示搜索条件
  234. showSearch: true,
  235. // 总条数
  236. total: 0,
  237. // 字典表格数据
  238. dataList: [],
  239. // 默认字典类型
  240. defaultDictType: "",
  241. // 弹出层标题
  242. title: "",
  243. // 是否显示弹出层
  244. open: false,
  245. // 数据标签回显样式
  246. listClassOptions: [
  247. {
  248. value: "default",
  249. label: "默认"
  250. },
  251. {
  252. value: "primary",
  253. label: "主要"
  254. },
  255. {
  256. value: "success",
  257. label: "成功"
  258. },
  259. {
  260. value: "info",
  261. label: "信息"
  262. },
  263. {
  264. value: "warning",
  265. label: "警告"
  266. },
  267. {
  268. value: "danger",
  269. label: "危险"
  270. }
  271. ],
  272. // 类型数据字典
  273. typeOptions: [],
  274. // 查询参数
  275. queryParams: {
  276. pageNum: 1,
  277. pageSize: 10,
  278. dictName: undefined,
  279. dictType: undefined,
  280. status: undefined
  281. },
  282. // 表单参数
  283. form: {},
  284. // 表单校验
  285. rules: {
  286. dictLabel: [
  287. { required: true, message: "数据标签不能为空", trigger: "blur" }
  288. ],
  289. dictValue: [
  290. { required: true, message: "数据键值不能为空", trigger: "blur" }
  291. ],
  292. dictSort: [
  293. { required: true, message: "数据顺序不能为空", trigger: "blur" }
  294. ]
  295. }
  296. };
  297. },
  298. created() {
  299. const dictId = this.$route.params && this.$route.params.dictId;
  300. this.getType(dictId);
  301. this.getTypeList();
  302. },
  303. methods: {
  304. /** 查询字典类型详细 */
  305. getType(dictId) {
  306. getType(dictId).then(response => {
  307. this.queryParams.dictType = response.data.dictType;
  308. this.defaultDictType = response.data.dictType;
  309. this.getList();
  310. });
  311. },
  312. /** 查询字典类型列表 */
  313. getTypeList() {
  314. getDictOptionselect().then(response => {
  315. this.typeOptions = response.data;
  316. });
  317. },
  318. /** 查询字典数据列表 */
  319. getList() {
  320. this.loading = true;
  321. listData(this.queryParams).then(response => {
  322. this.dataList = response.rows;
  323. this.total = response.total;
  324. this.loading = false;
  325. });
  326. },
  327. // 取消按钮
  328. cancel() {
  329. this.open = false;
  330. this.reset();
  331. },
  332. // 表单重置
  333. reset() {
  334. this.form = {
  335. dictCode: undefined,
  336. dictLabel: undefined,
  337. dictValue: undefined,
  338. cssClass: undefined,
  339. listClass: 'default',
  340. dictSort: 0,
  341. status: "0",
  342. remark: undefined
  343. };
  344. this.resetForm("form");
  345. },
  346. /** 搜索按钮操作 */
  347. handleQuery() {
  348. this.queryParams.pageNum = 1;
  349. this.getList();
  350. },
  351. /** 返回按钮操作 */
  352. handleClose() {
  353. const obj = { path: "/system/dict" };
  354. this.$tab.closeOpenPage(obj);
  355. },
  356. /** 重置按钮操作 */
  357. resetQuery() {
  358. this.resetForm("queryForm");
  359. this.queryParams.dictType = this.defaultDictType;
  360. this.handleQuery();
  361. },
  362. /** 新增按钮操作 */
  363. handleAdd() {
  364. this.reset();
  365. this.open = true;
  366. this.title = "新增";
  367. this.form.dictType = this.queryParams.dictType;
  368. },
  369. // 多选框选中数据
  370. handleSelectionChange(selection) {
  371. this.ids = selection.map(item => item.dictCode)
  372. this.single = selection.length!=1
  373. this.multiple = !selection.length
  374. },
  375. /** 修改按钮操作 */
  376. handleUpdate(row) {
  377. this.reset();
  378. const dictCode = row.dictCode || this.ids
  379. getData(dictCode).then(response => {
  380. this.form = response.data;
  381. this.open = true;
  382. this.title = "编辑";
  383. });
  384. },
  385. /** 提交按钮 */
  386. submitForm: function() {
  387. this.$refs["form"].validate(valid => {
  388. if (valid) {
  389. if (this.form.dictCode != undefined) {
  390. updateData(this.form).then(response => {
  391. this.$store.dispatch('dict/removeDict', this.queryParams.dictType);
  392. this.$modal.msgSuccess("处理成功");
  393. this.open = false;
  394. this.getList();
  395. });
  396. } else {
  397. addData(this.form).then(response => {
  398. this.$store.dispatch('dict/removeDict', this.queryParams.dictType);
  399. this.$modal.msgSuccess("处理成功");
  400. this.open = false;
  401. this.getList();
  402. });
  403. }
  404. }
  405. });
  406. },
  407. /** 删除按钮操作 */
  408. handleDelete(row) {
  409. const dictCodes = row.dictCode || this.ids;
  410. this.$modal.confirm('是否确认删除字典编码为"' + dictCodes + '"的数据项?').then(function() {
  411. return delData(dictCodes);
  412. }).then(() => {
  413. this.getList();
  414. this.$modal.msgSuccess("删除成功");
  415. this.$store.dispatch('dict/removeDict', this.queryParams.dictType);
  416. }).catch(() => {});
  417. },
  418. /** 导出按钮操作 */
  419. handleExport() {
  420. this.download('system/dict/data/export', {
  421. ...this.queryParams
  422. }, `data_${new Date().getTime()}.xlsx`)
  423. }
  424. }
  425. };
  426. </script>