data.vue 11 KB

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