华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

405 lines
13 KiB

  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :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 type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
  34. <el-button icon="el-icon-refresh" @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. icon="el-icon-plus"
  43. @click="handleAdd"
  44. v-hasPermi="['system:dict:add','system:dict:edit']"
  45. >新增</el-button>
  46. </el-col>
  47. <!-- <el-col :span="1.5">
  48. <el-button
  49. type="success"
  50. plain
  51. icon="el-icon-edit"
  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. icon="el-icon-delete"
  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. icon="el-icon-download"
  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. icon="el-icon-close"
  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
  111. type="text"
  112. @click="handleUpdate(scope.row,false)"
  113. v-hasPermi="['system:dict:edit']"
  114. >编辑</el-button>
  115. <el-button
  116. type="text"
  117. @click="handleDelete(scope.row)"
  118. v-hasPermi="['system:dict:remove']"
  119. >删除</el-button>
  120. <el-button
  121. type="text"
  122. @click="handleUpdate(scope.row,true)"
  123. v-hasPermi="['system:dict:query']"
  124. >详情</el-button>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. <pagination
  129. v-show="total>0"
  130. :total="total"
  131. :page.sync="queryParams.pageNum"
  132. :limit.sync="queryParams.pageSize"
  133. @pagination="getList"
  134. />
  135. <!-- 添加或修改参数配置对话框 -->
  136. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  137. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  138. <el-form-item label="字典类型">
  139. <el-input v-model="form.dictType" :disabled="true" />
  140. </el-form-item>
  141. <el-form-item label="标签" prop="dictLabel">
  142. <el-input v-model="form.dictLabel" placeholder="请输入数据标签" :readonly="readonly" />
  143. </el-form-item>
  144. <el-form-item label="键值" prop="dictValue">
  145. <el-input v-model="form.dictValue" placeholder="请输入数据键值" :readonly="readonly" />
  146. </el-form-item>
  147. <!-- <el-form-item label="样式属性" prop="cssClass">
  148. <el-input v-model="form.cssClass" placeholder="请输入样式属性" />
  149. </el-form-item> -->
  150. <el-form-item label="排序" prop="dictSort">
  151. <el-input-number v-model="form.dictSort" controls-position="right" :min="0" :disabled="readonly" />
  152. </el-form-item>
  153. <!-- <el-form-item label="回显样式" prop="listClass">
  154. <el-select v-model="form.listClass">
  155. <el-option
  156. v-for="item in listClassOptions"
  157. :key="item.value"
  158. :label="item.label + '(' + item.value + ')'"
  159. :value="item.value"
  160. ></el-option>
  161. </el-select>
  162. </el-form-item>
  163. <el-form-item label="状态" prop="status">
  164. <el-radio-group v-model="form.status">
  165. <el-radio
  166. v-for="dict in dict.type.sys_normal_disable"
  167. :key="dict.value"
  168. :label="dict.value"
  169. >{{dict.label}}</el-radio>
  170. </el-radio-group>
  171. </el-form-item> -->
  172. <el-form-item label="备注" prop="remark">
  173. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :readonly="readonly"></el-input>
  174. </el-form-item>
  175. </el-form>
  176. <div slot="footer" class="dialog-footer" v-if="!readonly">
  177. <el-button type="primary" @click="submitForm"> </el-button>
  178. <el-button @click="cancel"> </el-button>
  179. </div>
  180. </el-dialog>
  181. </div>
  182. </template>
  183. <script>
  184. import { listData, getData, delData, addData, updateData } from "@/api/system/dict/data"
  185. import { optionselect as getDictOptionselect, getType } from "@/api/system/dict/type"
  186. export default {
  187. name: "Data",
  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. dataList: [],
  205. // 默认字典类型
  206. defaultDictType: "",
  207. // 弹出层标题
  208. title: "",
  209. // 是否显示弹出层
  210. open: false,
  211. // 数据标签回显样式
  212. listClassOptions: [
  213. {
  214. value: "default",
  215. label: "默认"
  216. },
  217. {
  218. value: "primary",
  219. label: "主要"
  220. },
  221. {
  222. value: "success",
  223. label: "成功"
  224. },
  225. {
  226. value: "info",
  227. label: "信息"
  228. },
  229. {
  230. value: "warning",
  231. label: "警告"
  232. },
  233. {
  234. value: "danger",
  235. label: "危险"
  236. }
  237. ],
  238. // 类型数据字典
  239. typeOptions: [],
  240. // 查询参数
  241. queryParams: {
  242. pageNum: 1,
  243. pageSize: 10,
  244. dictType: undefined,
  245. dictLabel: undefined,
  246. status: undefined
  247. },
  248. // 表单参数
  249. form: {},
  250. // 表单校验
  251. rules: {
  252. dictLabel: [
  253. { required: true, message: "标签不能为空", trigger: "blur" }
  254. ],
  255. dictValue: [
  256. { required: true, message: "键值不能为空", trigger: "blur" }
  257. ],
  258. dictSort: [
  259. { required: true, message: "顺序不能为空", trigger: "blur" }
  260. ]
  261. }
  262. }
  263. },
  264. created() {
  265. const dictId = this.$route.params && this.$route.params.dictId
  266. this.getType(dictId)
  267. this.getTypeList()
  268. },
  269. methods: {
  270. /** 查询字典类型详细 */
  271. getType(dictId) {
  272. getType(dictId).then(response => {
  273. this.queryParams.dictType = response.data.dictType
  274. this.defaultDictType = response.data.dictType
  275. this.getList()
  276. })
  277. },
  278. /** 查询字典类型列表 */
  279. getTypeList() {
  280. getDictOptionselect().then(response => {
  281. this.typeOptions = response.data
  282. })
  283. },
  284. /** 查询字典数据列表 */
  285. getList() {
  286. this.loading = true
  287. listData(this.queryParams).then(response => {
  288. this.dataList = response.rows
  289. this.total = response.total
  290. this.loading = false
  291. })
  292. },
  293. // 取消按钮
  294. cancel() {
  295. this.open = false
  296. this.reset()
  297. },
  298. // 表单重置
  299. reset() {
  300. this.form = {
  301. dictCode: undefined,
  302. dictLabel: undefined,
  303. dictValue: undefined,
  304. cssClass: undefined,
  305. listClass: 'default',
  306. dictSort: 0,
  307. status: "0",
  308. remark: undefined
  309. }
  310. this.resetForm("form")
  311. },
  312. /** 搜索按钮操作 */
  313. handleQuery() {
  314. this.queryParams.pageNum = 1
  315. this.getList()
  316. },
  317. /** 返回按钮操作 */
  318. handleClose() {
  319. const obj = { path: "/system/dict" }
  320. this.$tab.closeOpenPage(obj)
  321. },
  322. /** 重置按钮操作 */
  323. resetQuery() {
  324. this.resetForm("queryForm")
  325. this.queryParams.dictType = this.defaultDictType
  326. this.handleQuery()
  327. },
  328. /** 新增按钮操作 */
  329. handleAdd() {
  330. this.reset()
  331. this.open = true
  332. this.title = "添加字典数据"
  333. this.form.dictType = this.queryParams.dictType
  334. },
  335. // 多选框选中数据
  336. handleSelectionChange(selection) {
  337. this.ids = selection.map(item => item.dictCode)
  338. this.single = selection.length!=1
  339. this.multiple = !selection.length
  340. },
  341. /** 修改按钮操作 */
  342. handleUpdate(row,readonly) {
  343. this.readonly = readonly
  344. this.reset()
  345. const dictCode = row.dictCode || this.ids
  346. getData(dictCode).then(response => {
  347. this.form = response.data
  348. this.open = true
  349. this.title = (readonly?'':'编辑')+"字典数据"
  350. })
  351. },
  352. /** 提交按钮 */
  353. submitForm: function() {
  354. this.$refs["form"].validate(valid => {
  355. if (valid) {
  356. if (this.form.dictCode != undefined) {
  357. updateData(this.form).then(response => {
  358. this.$store.dispatch('dict/removeDict', this.queryParams.dictType)
  359. this.open = false
  360. this.getList()
  361. })
  362. } else {
  363. addData(this.form).then(response => {
  364. this.$store.dispatch('dict/removeDict', this.queryParams.dictType)
  365. this.open = false
  366. this.getList()
  367. })
  368. }
  369. }
  370. })
  371. },
  372. /** 删除按钮操作 */
  373. handleDelete(row) {
  374. const dictCodes = row.dictCode || this.ids
  375. this.$modal.confirm('是否确认删除字典编码为"' + dictCodes + '"的数据项?').then(function() {
  376. return delData(dictCodes)
  377. }).then(() => {
  378. this.getList()
  379. this.$store.dispatch('dict/removeDict', this.queryParams.dictType)
  380. }).catch(() => {})
  381. },
  382. /** 导出按钮操作 */
  383. handleExport() {
  384. this.download('system/dict/data/export', {
  385. ...this.queryParams
  386. }, `data_${new Date().getTime()}.xlsx`)
  387. }
  388. }
  389. }
  390. </script>