data.vue 10 KB

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