index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-position="top">
  4. <el-row :gutter="20">
  5. <el-col :span="6">
  6. <el-form-item label="字典名称" prop="dictName">
  7. <el-input v-model="queryParams.dictName" placeholder="请输入字典名称" clearable
  8. @keyup.enter.native="handleQuery" />
  9. </el-form-item>
  10. </el-col>
  11. <el-col :span="6">
  12. <el-form-item label="字典类型" prop="dictType">
  13. <el-input v-model="queryParams.dictType" placeholder="请输入字典类型" clearable
  14. @keyup.enter.native="handleQuery" />
  15. </el-form-item>
  16. </el-col>
  17. <el-col :span="6">
  18. <el-form-item label="状态" prop="status">
  19. <el-select v-model="queryParams.status" placeholder="字典状态" clearable style="width: 100%;">
  20. <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
  21. :value="dict.value" />
  22. </el-select>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="6">
  26. <el-form-item label="创建时间">
  27. <el-date-picker v-model="dateRange" style="width: 100%;" value-format="yyyy-MM-dd" type="daterange"
  28. range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  29. </el-form-item>
  30. </el-col>
  31. </el-row>
  32. <el-row :gutter="20">
  33. <el-col :span="6">
  34. <el-form-item label="搜索">
  35. <el-button style="width: 100%;" type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  36. </el-form-item>
  37. </el-col>
  38. <el-col :span="6">
  39. <el-form-item label="重置">
  40. <el-button style="width: 100%;" icon="el-icon-refresh" type="primary" @click="resetQuery">重置</el-button>
  41. </el-form-item>
  42. </el-col>
  43. </el-row>
  44. </el-form>
  45. <el-row :gutter="10" class="mb8">
  46. <el-col :span="1.5">
  47. <el-button type="primary" icon="el-icon-plus" size="small" @click="handleAdd"
  48. v-hasPermi="['system:dict:add']">新增</el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button type="success" class="editButton" icon="el-icon-edit" size="small" :disabled="single" @click="handleUpdate"
  52. v-hasPermi="['system:dict:edit']">修改</el-button>
  53. </el-col>
  54. <el-col :span="1.5">
  55. <el-button type="danger" icon="el-icon-delete" size="small" :disabled="multiple" @click="handleDelete"
  56. v-hasPermi="['system:dict:remove']">删除</el-button>
  57. </el-col>
  58. <el-col :span="1.5">
  59. <el-button type="warning" icon="el-icon-download" size="small" @click="handleExport"
  60. v-hasPermi="['system:dict:export']">导出</el-button>
  61. </el-col>
  62. <el-col :span="1.5">
  63. <el-button type="danger" icon="el-icon-refresh" size="small" @click="handleRefreshCache"
  64. v-hasPermi="['system:dict:remove']">刷新缓存</el-button>
  65. </el-col>
  66. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  67. </el-row>
  68. <div class="border-card">
  69. <el-table height="450" v-loading="loading" border :data="typeList" @selection-change="handleSelectionChange">
  70. <el-table-column type="selection" width="55" align="center" />
  71. <el-table-column label="字典编号" align="center" prop="dictId" />
  72. <el-table-column label="字典名称" align="center" prop="dictName" :show-overflow-tooltip="true" />
  73. <el-table-column label="字典类型" align="center" :show-overflow-tooltip="true">
  74. <template slot-scope="scope">
  75. <router-link :to="'/system/dict-data/index/' + scope.row.dictId" class="link-type">
  76. <span>{{ scope.row.dictType }}</span>
  77. </router-link>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="状态" align="center" prop="status">
  81. <template slot-scope="scope">
  82. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status" />
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  86. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  87. <template slot-scope="scope">
  88. <span>{{ parseTime(scope.row.createTime) }}</span>
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  92. <template slot-scope="scope">
  93. <el-button size="small" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  94. v-hasPermi="['system:dict:edit']">修改</el-button>
  95. <el-button class="custom-red-color" size="small" type="text" icon="el-icon-delete"
  96. @click="handleDelete(scope.row)" v-hasPermi="['system:dict:remove']">删除</el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  101. @pagination="getList" />
  102. </div>
  103. <!-- 添加或修改参数配置对话框 -->
  104. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  105. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  106. <el-form-item label="字典名称" prop="dictName">
  107. <el-input v-model="form.dictName" placeholder="请输入字典名称" />
  108. </el-form-item>
  109. <el-form-item label="字典类型" prop="dictType">
  110. <el-input v-model="form.dictType" placeholder="请输入字典类型" />
  111. </el-form-item>
  112. <el-form-item label="状态" prop="status">
  113. <el-radio-group v-model="form.status">
  114. <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value"
  115. :label="dict.value">{{ dict.label }}</el-radio>
  116. </el-radio-group>
  117. </el-form-item>
  118. <el-form-item label="备注" prop="remark">
  119. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  120. </el-form-item>
  121. </el-form>
  122. <div slot="footer" class="dialog-footer">
  123. <el-button type="primary" @click="submitForm">确 定</el-button>
  124. <el-button @click="cancel">取 消</el-button>
  125. </div>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. import { listType, getType, delType, addType, updateType, refreshCache } from "@/api/system/dict/type";
  131. export default {
  132. name: "Dict",
  133. dicts: ['sys_normal_disable'],
  134. data() {
  135. return {
  136. // 遮罩层
  137. loading: true,
  138. // 选中数组
  139. ids: [],
  140. // 非单个禁用
  141. single: true,
  142. // 非多个禁用
  143. multiple: true,
  144. // 显示搜索条件
  145. showSearch: true,
  146. // 总条数
  147. total: 0,
  148. // 字典表格数据
  149. typeList: [],
  150. // 弹出层标题
  151. title: "",
  152. // 是否显示弹出层
  153. open: false,
  154. // 日期范围
  155. dateRange: [],
  156. // 查询参数
  157. queryParams: {
  158. pageNum: 1,
  159. pageSize: 10,
  160. dictName: undefined,
  161. dictType: undefined,
  162. status: undefined
  163. },
  164. // 表单参数
  165. form: {},
  166. // 表单校验
  167. rules: {
  168. dictName: [
  169. { required: true, message: "字典名称不能为空", trigger: "blur" }
  170. ],
  171. dictType: [
  172. { required: true, message: "字典类型不能为空", trigger: "blur" }
  173. ]
  174. }
  175. };
  176. },
  177. created() {
  178. this.getList();
  179. },
  180. methods: {
  181. /** 查询字典类型列表 */
  182. getList() {
  183. this.loading = true;
  184. listType(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  185. this.typeList = response.rows;
  186. this.total = response.total;
  187. this.loading = false;
  188. }
  189. );
  190. },
  191. // 取消按钮
  192. cancel() {
  193. this.open = false;
  194. this.reset();
  195. },
  196. // 表单重置
  197. reset() {
  198. this.form = {
  199. dictId: undefined,
  200. dictName: undefined,
  201. dictType: undefined,
  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. resetQuery() {
  214. this.dateRange = [];
  215. this.resetForm("queryForm");
  216. this.handleQuery();
  217. },
  218. /** 新增按钮操作 */
  219. handleAdd() {
  220. this.reset();
  221. this.open = true;
  222. this.title = "添加字典类型";
  223. },
  224. // 多选框选中数据
  225. handleSelectionChange(selection) {
  226. this.ids = selection.map(item => item.dictId)
  227. this.single = selection.length != 1
  228. this.multiple = !selection.length
  229. },
  230. /** 修改按钮操作 */
  231. handleUpdate(row) {
  232. this.reset();
  233. const dictId = row.dictId || this.ids
  234. getType(dictId).then(response => {
  235. this.form = response.data;
  236. this.open = true;
  237. this.title = "修改字典类型";
  238. });
  239. },
  240. /** 提交按钮 */
  241. submitForm: function () {
  242. this.$refs["form"].validate(valid => {
  243. if (valid) {
  244. if (this.form.dictId != undefined) {
  245. updateType(this.form).then(response => {
  246. this.$modal.msgSuccess("修改成功");
  247. this.open = false;
  248. this.getList();
  249. });
  250. } else {
  251. addType(this.form).then(response => {
  252. this.$modal.msgSuccess("新增成功");
  253. this.open = false;
  254. this.getList();
  255. });
  256. }
  257. }
  258. });
  259. },
  260. /** 删除按钮操作 */
  261. handleDelete(row) {
  262. const dictIds = row.dictId || this.ids;
  263. this.$modal.confirm('是否确认删除字典编号为"' + dictIds + '"的数据项?').then(function () {
  264. return delType(dictIds);
  265. }).then(() => {
  266. this.getList();
  267. this.$modal.msgSuccess("删除成功");
  268. }).catch(() => { });
  269. },
  270. /** 导出按钮操作 */
  271. handleExport() {
  272. this.download('system/dict/type/export', {
  273. ...this.queryParams
  274. }, `type_${new Date().getTime()}.xlsx`)
  275. },
  276. /** 刷新缓存按钮操作 */
  277. handleRefreshCache() {
  278. refreshCache().then(() => {
  279. this.$modal.msgSuccess("刷新成功");
  280. this.$store.dispatch('dict/cleanDict');
  281. });
  282. }
  283. }
  284. };
  285. </script>