data.vue 13 KB

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