index.vue 11 KB

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