data.vue 13 KB

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