index.vue 10 KB

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