data.vue 11 KB

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