data.vue 9.9 KB

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