data.vue 13 KB

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