data.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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 v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
  92. <el-table-column type="selection" width="55" align="center" />
  93. <el-table-column label="字典编码" align="center" prop="dictCode" />
  94. <el-table-column label="字典标签" align="center" prop="dictLabel">
  95. <template slot-scope="scope">
  96. <span v-if="scope.row.listClass == '' || scope.row.listClass == 'default'">{{scope.row.dictLabel}}</span>
  97. <el-tag v-else :type="scope.row.listClass == 'primary' ? '' : scope.row.listClass">{{scope.row.dictLabel}}</el-tag>
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="字典键值" align="center" prop="dictValue" />
  101. <el-table-column label="字典排序" align="center" prop="dictSort" />
  102. <el-table-column label="状态" align="center" prop="status">
  103. <template slot-scope="scope">
  104. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
  105. </template>
  106. </el-table-column>
  107. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  108. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  109. <template slot-scope="scope">
  110. <span>{{ parseTime(scope.row.createTime) }}</span>
  111. </template>
  112. </el-table-column>
  113. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  114. <template slot-scope="scope">
  115. <el-button
  116. size="mini"
  117. type="text"
  118. icon="el-icon-edit"
  119. @click="handleUpdate(scope.row)"
  120. v-hasPermi="['system:dict:edit']"
  121. >修改</el-button>
  122. <el-button
  123. size="mini"
  124. type="text"
  125. icon="el-icon-delete"
  126. @click="handleDelete(scope.row)"
  127. v-hasPermi="['system:dict:remove']"
  128. >删除</el-button>
  129. </template>
  130. </el-table-column>
  131. </el-table>
  132. <pagination
  133. v-show="total>0"
  134. :total="total"
  135. :page.sync="queryParams.pageNum"
  136. :limit.sync="queryParams.pageSize"
  137. @pagination="getList"
  138. />
  139. <!-- 添加或修改参数配置对话框 -->
  140. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  141. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  142. <el-form-item label="字典类型">
  143. <el-input v-model="form.dictType" :disabled="true" />
  144. </el-form-item>
  145. <el-form-item label="数据标签" prop="dictLabel">
  146. <el-input v-model="form.dictLabel" placeholder="请输入数据标签" />
  147. </el-form-item>
  148. <el-form-item label="数据键值" prop="dictValue">
  149. <el-input v-model="form.dictValue" placeholder="请输入数据键值" />
  150. </el-form-item>
  151. <el-form-item label="样式属性" prop="cssClass">
  152. <el-input v-model="form.cssClass" placeholder="请输入样式属性" />
  153. </el-form-item>
  154. <el-form-item label="显示排序" prop="dictSort">
  155. <el-input-number v-model="form.dictSort" controls-position="right" :min="0" />
  156. </el-form-item>
  157. <el-form-item label="回显样式" prop="listClass">
  158. <el-select v-model="form.listClass">
  159. <el-option
  160. v-for="item in listClassOptions"
  161. :key="item.value"
  162. :label="item.label"
  163. :value="item.value"
  164. ></el-option>
  165. </el-select>
  166. </el-form-item>
  167. <el-form-item label="状态" prop="status">
  168. <el-radio-group v-model="form.status">
  169. <el-radio
  170. v-for="dict in dict.type.sys_normal_disable"
  171. :key="dict.value"
  172. :label="dict.value"
  173. >{{dict.label}}</el-radio>
  174. </el-radio-group>
  175. </el-form-item>
  176. <el-form-item label="备注" prop="remark">
  177. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  178. </el-form-item>
  179. </el-form>
  180. <div slot="footer" class="dialog-footer">
  181. <el-button type="primary" @click="submitForm">确 定</el-button>
  182. <el-button @click="cancel">取 消</el-button>
  183. </div>
  184. </el-dialog>
  185. </div>
  186. </template>
  187. <script>
  188. import { listData, getData, delData, addData, updateData } from "@/api/system/dict/data";
  189. import { listType, getType } from "@/api/system/dict/type";
  190. export default {
  191. name: "Data",
  192. dicts: ['sys_normal_disable'],
  193. data() {
  194. return {
  195. // 遮罩层
  196. loading: true,
  197. // 选中数组
  198. ids: [],
  199. // 非单个禁用
  200. single: true,
  201. // 非多个禁用
  202. multiple: true,
  203. // 显示搜索条件
  204. showSearch: true,
  205. // 总条数
  206. total: 0,
  207. // 字典表格数据
  208. dataList: [],
  209. // 默认字典类型
  210. defaultDictType: "",
  211. // 弹出层标题
  212. title: "",
  213. // 是否显示弹出层
  214. open: false,
  215. // 数据标签回显样式
  216. listClassOptions: [
  217. {
  218. value: "default",
  219. label: "默认"
  220. },
  221. {
  222. value: "primary",
  223. label: "主要"
  224. },
  225. {
  226. value: "success",
  227. label: "成功"
  228. },
  229. {
  230. value: "info",
  231. label: "信息"
  232. },
  233. {
  234. value: "warning",
  235. label: "警告"
  236. },
  237. {
  238. value: "danger",
  239. label: "危险"
  240. }
  241. ],
  242. // 类型数据字典
  243. typeOptions: [],
  244. // 查询参数
  245. queryParams: {
  246. pageNum: 1,
  247. pageSize: 10,
  248. dictName: undefined,
  249. dictType: undefined,
  250. status: undefined
  251. },
  252. // 表单参数
  253. form: {},
  254. // 表单校验
  255. rules: {
  256. dictLabel: [
  257. { required: true, message: "数据标签不能为空", trigger: "blur" }
  258. ],
  259. dictValue: [
  260. { required: true, message: "数据键值不能为空", trigger: "blur" }
  261. ],
  262. dictSort: [
  263. { required: true, message: "数据顺序不能为空", trigger: "blur" }
  264. ]
  265. }
  266. };
  267. },
  268. created() {
  269. const dictId = this.$route.params && this.$route.params.dictId;
  270. this.getType(dictId);
  271. this.getTypeList();
  272. },
  273. methods: {
  274. /** 查询字典类型详细 */
  275. getType(dictId) {
  276. getType(dictId).then(response => {
  277. this.queryParams.dictType = response.data.dictType;
  278. this.defaultDictType = response.data.dictType;
  279. this.getList();
  280. });
  281. },
  282. /** 查询字典类型列表 */
  283. getTypeList() {
  284. listType().then(response => {
  285. this.typeOptions = response.rows;
  286. });
  287. },
  288. /** 查询字典数据列表 */
  289. getList() {
  290. this.loading = true;
  291. listData(this.queryParams).then(response => {
  292. this.dataList = response.rows;
  293. this.total = response.total;
  294. this.loading = false;
  295. });
  296. },
  297. // 取消按钮
  298. cancel() {
  299. this.open = false;
  300. this.reset();
  301. },
  302. // 表单重置
  303. reset() {
  304. this.form = {
  305. dictCode: undefined,
  306. dictLabel: undefined,
  307. dictValue: undefined,
  308. cssClass: undefined,
  309. listClass: 'default',
  310. dictSort: 0,
  311. status: "0",
  312. remark: undefined
  313. };
  314. this.resetForm("form");
  315. },
  316. /** 搜索按钮操作 */
  317. handleQuery() {
  318. this.queryParams.pageNum = 1;
  319. this.getList();
  320. },
  321. /** 返回按钮操作 */
  322. handleClose() {
  323. const obj = { path: "/system/dict" };
  324. this.$tab.closeOpenPage(obj);
  325. },
  326. /** 重置按钮操作 */
  327. resetQuery() {
  328. this.resetForm("queryForm");
  329. this.queryParams.dictType = this.defaultDictType;
  330. this.handleQuery();
  331. },
  332. /** 新增按钮操作 */
  333. handleAdd() {
  334. this.reset();
  335. this.open = true;
  336. this.title = "添加字典数据";
  337. this.form.dictType = this.queryParams.dictType;
  338. },
  339. // 多选框选中数据
  340. handleSelectionChange(selection) {
  341. this.ids = selection.map(item => item.dictCode)
  342. this.single = selection.length!=1
  343. this.multiple = !selection.length
  344. },
  345. /** 修改按钮操作 */
  346. handleUpdate(row) {
  347. this.reset();
  348. const dictCode = row.dictCode || this.ids
  349. getData(dictCode).then(response => {
  350. this.form = response.data;
  351. this.open = true;
  352. this.title = "修改字典数据";
  353. });
  354. },
  355. /** 提交按钮 */
  356. submitForm: function() {
  357. this.$refs["form"].validate(valid => {
  358. if (valid) {
  359. if (this.form.dictCode != undefined) {
  360. updateData(this.form).then(response => {
  361. this.$modal.msgSuccess("修改成功");
  362. this.open = false;
  363. this.getList();
  364. });
  365. } else {
  366. addData(this.form).then(response => {
  367. this.$modal.msgSuccess("新增成功");
  368. this.open = false;
  369. this.getList();
  370. });
  371. }
  372. }
  373. });
  374. },
  375. /** 删除按钮操作 */
  376. handleDelete(row) {
  377. const dictCodes = row.dictCode || this.ids;
  378. this.$modal.confirm('是否确认删除字典编码为"' + dictCodes + '"的数据项?').then(function() {
  379. return delData(dictCodes);
  380. }).then(() => {
  381. this.getList();
  382. this.$modal.msgSuccess("删除成功");
  383. }).catch(() => {});
  384. },
  385. /** 导出按钮操作 */
  386. handleExport() {
  387. this.download('system/dict/data/export', {
  388. ...this.queryParams
  389. }, `data_${new Date().getTime()}.xlsx`)
  390. }
  391. }
  392. };
  393. </script>