data.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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="dictType">
  5. <el-select v-model="queryParams.dictType">
  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. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="状态" prop="status">
  23. <el-select v-model="queryParams.status" placeholder="数据状态" clearable>
  24. <el-option
  25. v-for="dict in dict.type.sys_normal_disable"
  26. :key="dict.value"
  27. :label="dict.label"
  28. :value="dict.value"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button style="background-color: #03BF8A; border-color: #03BF8A;" type="primary" size="mini" @click="handleQuery">搜索</el-button>
  34. <el-button size="mini" @click="resetQuery">重置</el-button>
  35. </el-form-item>
  36. </el-form>
  37. <el-row :gutter="10" class="mb8">
  38. <el-col :span="1.5">
  39. <el-button
  40. type="primary"
  41. plain
  42. size="mini"
  43. @click="handleAdd"
  44. v-hasPermi="['system:dict:add']"
  45. >新增</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button
  49. type="success"
  50. plain
  51. size="mini"
  52. :disabled="single"
  53. @click="handleUpdate"
  54. v-hasPermi="['system:dict:edit']"
  55. >修改</el-button>
  56. </el-col>
  57. <el-col :span="1.5">
  58. <el-button
  59. type="danger"
  60. plain
  61. size="mini"
  62. :disabled="multiple"
  63. @click="handleDelete"
  64. v-hasPermi="['system:dict:remove']"
  65. >删除</el-button>
  66. </el-col>
  67. <el-col :span="1.5">
  68. <el-button
  69. type="warning"
  70. plain
  71. size="mini"
  72. @click="handleExport"
  73. v-hasPermi="['system:dict:export']"
  74. >导出</el-button>
  75. </el-col>
  76. <el-col :span="1.5">
  77. <el-button
  78. type="warning"
  79. plain
  80. size="mini"
  81. @click="handleClose"
  82. >关闭</el-button>
  83. </el-col>
  84. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  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. <template slot-scope="scope">
  91. <span v-if="(scope.row.listClass == '' || scope.row.listClass == 'default') && (scope.row.cssClass == '' || scope.row.cssClass == null)">{{ scope.row.dictLabel }}</span>
  92. <el-tag v-else :type="scope.row.listClass == 'primary' ? '' : scope.row.listClass" :class="scope.row.cssClass">{{ scope.row.dictLabel }}</el-tag>
  93. </template>
  94. </el-table-column>
  95. <el-table-column label="字典键值" align="center" prop="dictValue" />
  96. <el-table-column label="字典排序" align="center" prop="dictSort" />
  97. <el-table-column label="状态" align="center" prop="status">
  98. <template slot-scope="scope">
  99. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  103. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  104. <template slot-scope="scope">
  105. <span>{{ parseTime(scope.row.createTime) }}</span>
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  109. <template slot-scope="scope">
  110. <el-button size="mini" style="width: 42px;height: 26px;
  111. background: #E5F9F3;
  112. border-radius: 4px;border: 1px solid #03BF8A;color: #03BF8A;
  113. " type="text" plain @click="handleUpdate(scope.row)"
  114. v-hasPermi="['system:dict:edit']">修改</el-button>
  115. <el-button size="mini" type="text" style="width: 42px;height: 26px;background: #FFF1EA;
  116. border-radius: 4px;border: 1px solid #FE570E;color: #FE570E;"
  117. @click="handleDelete(scope.row)" v-hasPermi="['system:dict:remove']" >删除</el-button>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. <pagination
  122. v-show="total>0"
  123. :total="total"
  124. :page.sync="queryParams.pageNum"
  125. :limit.sync="queryParams.pageSize"
  126. @pagination="getList"
  127. />
  128. <!-- 添加或修改参数配置对话框 -->
  129. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  130. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  131. <el-form-item label="字典类型">
  132. <el-input v-model="form.dictType" :disabled="true" />
  133. </el-form-item>
  134. <el-form-item label="数据标签" prop="dictLabel">
  135. <el-input v-model="form.dictLabel" placeholder="请输入数据标签" />
  136. </el-form-item>
  137. <el-form-item label="数据键值" prop="dictValue">
  138. <el-input v-model="form.dictValue" placeholder="请输入数据键值" />
  139. </el-form-item>
  140. <el-form-item label="样式属性" prop="cssClass">
  141. <el-input v-model="form.cssClass" placeholder="请输入样式属性" />
  142. </el-form-item>
  143. <el-form-item label="显示排序" prop="dictSort">
  144. <el-input-number v-model="form.dictSort" controls-position="right" :min="0" />
  145. </el-form-item>
  146. <el-form-item label="回显样式" prop="listClass">
  147. <el-select v-model="form.listClass">
  148. <el-option
  149. v-for="item in listClassOptions"
  150. :key="item.value"
  151. :label="item.label + '(' + item.value + ')'"
  152. :value="item.value"
  153. ></el-option>
  154. </el-select>
  155. </el-form-item>
  156. <el-form-item label="状态" prop="status">
  157. <el-radio-group v-model="form.status">
  158. <el-radio
  159. v-for="dict in dict.type.sys_normal_disable"
  160. :key="dict.value"
  161. :label="dict.value"
  162. >{{dict.label}}</el-radio>
  163. </el-radio-group>
  164. </el-form-item>
  165. <el-form-item label="备注" prop="remark">
  166. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  167. </el-form-item>
  168. </el-form>
  169. <div slot="footer" class="dialog-footer">
  170. <el-button type="primary" @click="submitForm">确 定</el-button>
  171. <el-button @click="cancel">取 消</el-button>
  172. </div>
  173. </el-dialog>
  174. </div>
  175. </template>
  176. <script>
  177. import { listData, getData, delData, addData, updateData } from "@/api/system/dict/data"
  178. import { optionselect as getDictOptionselect, getType } from "@/api/system/dict/type"
  179. export default {
  180. name: "Data",
  181. dicts: ['sys_normal_disable'],
  182. data() {
  183. return {
  184. // 遮罩层
  185. loading: true,
  186. // 选中数组
  187. ids: [],
  188. // 非单个禁用
  189. single: true,
  190. // 非多个禁用
  191. multiple: true,
  192. // 显示搜索条件
  193. showSearch: true,
  194. // 总条数
  195. total: 0,
  196. // 字典表格数据
  197. dataList: [],
  198. // 默认字典类型
  199. defaultDictType: "",
  200. // 弹出层标题
  201. title: "",
  202. // 是否显示弹出层
  203. open: false,
  204. // 数据标签回显样式
  205. listClassOptions: [
  206. {
  207. value: "default",
  208. label: "默认"
  209. },
  210. {
  211. value: "primary",
  212. label: "主要"
  213. },
  214. {
  215. value: "success",
  216. label: "成功"
  217. },
  218. {
  219. value: "info",
  220. label: "信息"
  221. },
  222. {
  223. value: "warning",
  224. label: "警告"
  225. },
  226. {
  227. value: "danger",
  228. label: "危险"
  229. }
  230. ],
  231. // 类型数据字典
  232. typeOptions: [],
  233. // 查询参数
  234. queryParams: {
  235. pageNum: 1,
  236. pageSize: 10,
  237. dictType: undefined,
  238. dictLabel: undefined,
  239. status: undefined
  240. },
  241. // 表单参数
  242. form: {},
  243. // 表单校验
  244. rules: {
  245. dictLabel: [
  246. { required: true, message: "数据标签不能为空", trigger: "blur" }
  247. ],
  248. dictValue: [
  249. { required: true, message: "数据键值不能为空", trigger: "blur" }
  250. ],
  251. dictSort: [
  252. { required: true, message: "数据顺序不能为空", trigger: "blur" }
  253. ]
  254. }
  255. }
  256. },
  257. created() {
  258. const dictId = this.$route.params && this.$route.params.dictId
  259. this.getType(dictId)
  260. this.getTypeList()
  261. },
  262. methods: {
  263. /** 查询字典类型详细 */
  264. getType(dictId) {
  265. getType(dictId).then(response => {
  266. this.queryParams.dictType = response.data.dictType
  267. this.defaultDictType = response.data.dictType
  268. this.getList()
  269. })
  270. },
  271. /** 查询字典类型列表 */
  272. getTypeList() {
  273. getDictOptionselect().then(response => {
  274. this.typeOptions = response.data
  275. })
  276. },
  277. /** 查询字典数据列表 */
  278. getList() {
  279. this.loading = true
  280. listData(this.queryParams).then(response => {
  281. this.dataList = response.rows
  282. this.total = response.total
  283. this.loading = false
  284. })
  285. },
  286. // 取消按钮
  287. cancel() {
  288. this.open = false
  289. this.reset()
  290. },
  291. // 表单重置
  292. reset() {
  293. this.form = {
  294. dictCode: undefined,
  295. dictLabel: undefined,
  296. dictValue: undefined,
  297. cssClass: undefined,
  298. listClass: 'default',
  299. dictSort: 0,
  300. status: "0",
  301. remark: undefined
  302. }
  303. this.resetForm("form")
  304. },
  305. /** 搜索按钮操作 */
  306. handleQuery() {
  307. this.queryParams.pageNum = 1
  308. this.getList()
  309. },
  310. /** 返回按钮操作 */
  311. handleClose() {
  312. const obj = { path: "/system/dict" }
  313. this.$tab.closeOpenPage(obj)
  314. },
  315. /** 重置按钮操作 */
  316. resetQuery() {
  317. this.resetForm("queryForm")
  318. this.queryParams.dictType = this.defaultDictType
  319. this.handleQuery()
  320. },
  321. /** 新增按钮操作 */
  322. handleAdd() {
  323. this.reset()
  324. this.open = true
  325. this.title = "添加字典数据"
  326. this.form.dictType = this.queryParams.dictType
  327. },
  328. // 多选框选中数据
  329. handleSelectionChange(selection) {
  330. this.ids = selection.map(item => item.dictCode)
  331. this.single = selection.length!=1
  332. this.multiple = !selection.length
  333. },
  334. /** 修改按钮操作 */
  335. handleUpdate(row) {
  336. this.reset()
  337. const dictCode = row.dictCode || this.ids
  338. getData(dictCode).then(response => {
  339. this.form = response.data
  340. this.open = true
  341. this.title = "修改字典数据"
  342. })
  343. },
  344. /** 提交按钮 */
  345. submitForm: function() {
  346. this.$refs["form"].validate(valid => {
  347. if (valid) {
  348. if (this.form.dictCode != undefined) {
  349. updateData(this.form).then(response => {
  350. this.$store.dispatch('dict/removeDict', this.queryParams.dictType)
  351. this.$modal.msgSuccess("修改成功")
  352. this.open = false
  353. this.getList()
  354. })
  355. } else {
  356. addData(this.form).then(response => {
  357. this.$store.dispatch('dict/removeDict', this.queryParams.dictType)
  358. this.$modal.msgSuccess("新增成功")
  359. this.open = false
  360. this.getList()
  361. })
  362. }
  363. }
  364. })
  365. },
  366. /** 删除按钮操作 */
  367. handleDelete(row) {
  368. const dictCodes = row.dictCode || this.ids
  369. this.$modal.confirm('是否确认删除字典编码为"' + dictCodes + '"的数据项?').then(function() {
  370. return delData(dictCodes)
  371. }).then(() => {
  372. this.getList()
  373. this.$modal.msgSuccess("删除成功")
  374. this.$store.dispatch('dict/removeDict', this.queryParams.dictType)
  375. }).catch(() => {})
  376. },
  377. /** 导出按钮操作 */
  378. handleExport() {
  379. this.download('system/dict/data/export', {
  380. ...this.queryParams
  381. }, `data_${new Date().getTime()}.xlsx`)
  382. }
  383. }
  384. }
  385. </script>