data.vue 11 KB

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