data.vue 9.0 KB

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