data.vue 12 KB

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