dictDataList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div class="app-container">
  3. <!-- 查询表单区域 -->
  4. <el-form :model="listQuery" size="small" :inline="true" label-position="top">
  5. <el-row :gutter="20">
  6. <el-col :span="6">
  7. <el-form-item label="字典名称">
  8. <el-select @change="changeDictType" v-model="listQuery.dictType" clearable filterable placeholder="请选择字典名称" style="width: 100%">
  9. <el-option :key="item.dictType" v-for="item in dictNameList" :label="item.dictName" :value="item.dictType">
  10. </el-option>
  11. </el-select>
  12. </el-form-item>
  13. </el-col>
  14. <el-col :span="6">
  15. <el-form-item label="字典标签">
  16. <el-input v-model="listQuery.dictLabel" placeholder="请输入字典标签" style="width: 100%" clearable></el-input>
  17. </el-form-item>
  18. </el-col>
  19. <el-col :span="6">
  20. <el-form-item label="状态">
  21. <el-select v-model="listQuery.status" clearable placeholder="请选择状态" style="width: 100%">
  22. <el-option :key="item.type" v-for="item in typeList" :label="item.name" :value="item.type">
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. </el-col>
  27. </el-row>
  28. <el-row :gutter="20">
  29. <el-col :span="6">
  30. <el-form-item label="搜索">
  31. <el-button style="width: 100%;" type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  32. </el-form-item>
  33. </el-col>
  34. <el-col :span="6">
  35. <el-form-item label="重置">
  36. <el-button style="width: 100%;" icon="el-icon-refresh" type="primary" @click="resetQuery">重置</el-button>
  37. </el-form-item>
  38. </el-col>
  39. </el-row>
  40. </el-form>
  41. <!-- 操作按钮区域 -->
  42. <el-row :gutter="10" class="mb8">
  43. <el-col :span="1.5">
  44. <el-button type="primary" class="editButton" size="small" icon="el-icon-plus" @click="handleCreate">添加</el-button>
  45. </el-col>
  46. <el-col :span="1.5">
  47. <el-button type="danger" icon="el-icon-delete" size="small" @click="delAll">批量删除</el-button>
  48. </el-col>
  49. </el-row>
  50. <!-- 表格区域 -->
  51. <div class="border-card">
  52. <el-table height="450" size="small" :data="list" v-loading="listLoading" @selection-change="handleSelectionChange" element-loading-text="正在查询中。。。" border fit highlight-current-row>
  53. <el-table-column type="selection" width="55px" align="center"></el-table-column>
  54. <el-table-column type="index" label="序号" header-align="center" align="center" width="55"></el-table-column>
  55. <el-table-column align="center" min-width="60px" label="字典编码" prop="dictCode"></el-table-column>
  56. <el-table-column align="center" min-width="100px" label="字典标签" prop="dictLabel"></el-table-column>
  57. <el-table-column align="center" min-width="60px" label="字典键值" prop="dictValue"></el-table-column>
  58. <el-table-column align="center" min-width="60px" label="字典排序" prop="dictSort"></el-table-column>
  59. <el-table-column align="center" min-width="80px" label="状态">
  60. <template slot-scope="scope">
  61. <el-tag v-if="scope.row.status == '0'">正常</el-tag>
  62. <el-tag v-else>停用</el-tag>
  63. </template>
  64. </el-table-column>
  65. <el-table-column align="center" min-width="200px" label="备注" prop="remark"></el-table-column>
  66. <el-table-column align="center" min-width="100px" label="创建时间" prop="createTime"></el-table-column>
  67. <el-table-column align="center" label="操作" width="240px" class-name="small-padding fixed-width">
  68. <template slot-scope="scope">
  69. <el-button type="text" icon="el-icon-edit" class="editText" size="small" @click="handleUpdate(scope.row, false)">编辑</el-button>
  70. <el-button type="text" icon="el-icon-delete" class="deleteText" size="small" @click="handleDelete(scope.row)">删除</el-button>
  71. </template>
  72. </el-table-column>
  73. </el-table>
  74. <!-- 分页 -->
  75. <div class="pagination-container">
  76. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
  77. :current-page="listQuery.page" :page-sizes="[10, 20, 30, 50]" :page-size="listQuery.limit"
  78. layout="total, sizes, prev, pager, next, jumper" :total="total">
  79. </el-pagination>
  80. </div>
  81. </div>
  82. <!-- 添加或修改对话框 -->
  83. <el-dialog :close-on-click-modal="false" :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="40%">
  84. <el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="80px">
  85. <el-form-item label="字典类型" prop="dictType">
  86. <el-input disabled v-model="dataForm.dictType" placeholder="字典类型"></el-input>
  87. </el-form-item>
  88. <el-form-item label="字典标签" prop="dictLabel">
  89. <el-input v-model="dataForm.dictLabel" placeholder="请输入字典标签"></el-input>
  90. </el-form-item>
  91. <el-form-item label="字典键值" prop="dictValue">
  92. <el-input v-model="dataForm.dictValue" placeholder="请输入字典键值"></el-input>
  93. </el-form-item>
  94. <el-form-item label="显示排序" prop="dictSort">
  95. <el-input-number :precision="0" :step="1" v-model="dataForm.dictSort"></el-input-number>
  96. </el-form-item>
  97. <el-form-item label="状态">
  98. <el-radio-group v-model="dataForm.status">
  99. <el-radio :label="'0'">正常</el-radio>
  100. <el-radio :label="'1'">停用</el-radio>
  101. </el-radio-group>
  102. </el-form-item>
  103. <el-form-item label="备注">
  104. <el-input type="textarea" :rows="2" v-model="dataForm.remark" placeholder="请输入备注"></el-input>
  105. </el-form-item>
  106. </el-form>
  107. <div slot="footer" class="dialog-footer">
  108. <el-button @click="dialogFormVisible = false">取消</el-button>
  109. <el-button v-if="dialogStatus == 'create'" type="primary" @click="createData">确定</el-button>
  110. <el-button v-else type="primary" @click="updateData">确定</el-button>
  111. </div>
  112. </el-dialog>
  113. </div>
  114. </template>
  115. <style>
  116. .demo-table-expand {
  117. font-size: 0;
  118. }
  119. .demo-table-expand label {
  120. width: 200px;
  121. color: #99a9bf;
  122. }
  123. .demo-table-expand .el-form-item {
  124. margin-right: 0;
  125. margin-bottom: 0;
  126. }
  127. </style>
  128. <script>
  129. import { dataList, dataAdd, dataEdit, dataRemove, optionSelect } from "@/api/dictManage";
  130. import waves from "@/directive/waves"; // 水波纹指令
  131. import Tinymce from '@/components/Tinymce'
  132. export default {
  133. components: { Tinymce },
  134. directives: { waves },
  135. data() {
  136. return {
  137. dictType:'',
  138. dictNameList: [],
  139. typeList: [
  140. {
  141. type: '0',
  142. name: "正常",
  143. },
  144. {
  145. type: '1',
  146. name: "停用",
  147. },
  148. ],
  149. list: [
  150. ],
  151. delarr: [],
  152. multipleSelection: [],
  153. total: 0,
  154. listLoading: false,
  155. listQuery: {
  156. page: 1,
  157. limit: 10,
  158. dictType: '',
  159. dictLabel: '',
  160. status: '',
  161. },
  162. dataForm: {
  163. dictType: undefined,
  164. dictLabel: undefined,
  165. dictValue: undefined,
  166. dictSort: undefined,
  167. status: '0',
  168. remark: undefined,
  169. },
  170. dialogFormVisible: false,
  171. dialogStatus: '',
  172. textMap: {
  173. update: "编辑",
  174. create: "创建",
  175. },
  176. imageUrl: undefined,
  177. rules: {
  178. dictLabel: [{ required: true, message: "字典标签不能为空", trigger: "blur" }],
  179. dictValue: [{ required: true, message: "字典键值不能为空", trigger: "blur" }],
  180. dictSort: [{ required: true, message: "显示排序不能为空", trigger: "blur" }],
  181. },
  182. }
  183. },
  184. created() {
  185. this.dictType = this.$route.params.id;
  186. this.getOptionSelect();
  187. },
  188. methods: {
  189. changeDictType(val){
  190. this.dictType = val;
  191. this.listQuery.dictType = val;
  192. this.getList();
  193. },
  194. getOptionSelect(){
  195. optionSelect().then(response => {
  196. this.dictNameList = response.data.data;
  197. this.listQuery.dictType = this.dictType;
  198. this.getList();
  199. }).catch(() => {})
  200. },
  201. resetForm() {
  202. this.dataForm = {
  203. dictType: undefined,
  204. dictLabel: undefined,
  205. dictValue: undefined,
  206. dictSort: undefined,
  207. status: '0',
  208. remark: undefined,
  209. };
  210. },
  211. handleCreate() {
  212. this.resetForm();
  213. this.dataForm.dictType = this.dictType;
  214. this.dialogFormVisible = true;
  215. this.dialogStatus = "create";
  216. this.$nextTick(() => {
  217. this.$refs["dataForm"].clearValidate();
  218. });
  219. },
  220. createData() {
  221. this.$refs["dataForm"].validate((valid) => {
  222. if (valid) {
  223. dataAdd(this.dataForm)
  224. .then(() => {
  225. this.getList();
  226. this.dialogFormVisible = false;
  227. this.$notify({
  228. title: "成功",
  229. message: "创建成功",
  230. type: "success",
  231. duration: 2000,
  232. });
  233. this.getList()
  234. })
  235. }
  236. });
  237. },
  238. getList() {
  239. this.listLoading = true
  240. dataList(this.listQuery).then(response => {
  241. this.list = response.data.data.items
  242. this.total = response.data.data.total
  243. this.listLoading = false
  244. }).catch(() => {
  245. this.list = []
  246. this.total = 0
  247. this.listLoading = false
  248. })
  249. },
  250. handleQuery() {
  251. this.listQuery.page = 1
  252. this.getList()
  253. },
  254. /** 重置按钮操作 */
  255. resetQuery() {
  256. this.listQuery = {
  257. dictType: '',
  258. dictLabel: '',
  259. status: '',
  260. };
  261. this.handleQuery();
  262. },
  263. handleSizeChange(val) {
  264. this.listQuery.limit = val
  265. this.getList()
  266. },
  267. handleCurrentChange(val) {
  268. this.listQuery.page = val
  269. this.getList()
  270. },
  271. handleUpdate(row) {
  272. this.dataForm = Object.assign({}, row);
  273. this.dialogStatus = 'update'
  274. this.dialogFormVisible = true
  275. this.$nextTick(() => {
  276. this.$refs['dataForm'].clearValidate()
  277. })
  278. },
  279. updateData() {
  280. this.$refs['dataForm'].validate((valid) => {
  281. if (valid) {
  282. dataEdit(this.dataForm).then(() => {
  283. this.dialogFormVisible = false
  284. this.$notify({
  285. title: '成功',
  286. message: '更新成功',
  287. type: 'success',
  288. duration: 2000
  289. })
  290. this.getList()
  291. })
  292. }
  293. })
  294. },
  295. handleDelete(row) {
  296. this.$confirm('确认删除吗?', '提示', {
  297. confirmButtonText: '确定',
  298. cancelButtonText: '取消',
  299. type: 'warning'
  300. }).then(() => {
  301. dataRemove({ dictCodes:row.dictCode}).then(response => {
  302. this.$notify({
  303. title: '成功',
  304. message: '删除成功',
  305. type: 'success',
  306. duration: 2000
  307. })
  308. const index = this.list.indexOf(row)
  309. this.list.splice(index, 1)
  310. })
  311. }).catch(() => {
  312. })
  313. },
  314. delAll() {
  315. this.$confirm("确认删除吗?", "提示", {
  316. confirmButtonText: "确定",
  317. cancelButtonText: "取消",
  318. type: "warning",
  319. })
  320. .then(() => {
  321. const length = this.multipleSelection.length;
  322. if (length > 0) {
  323. for (let i = 0; i < length; i++) {
  324. this.delarr.push(this.multipleSelection[i].dictCode);
  325. }
  326. const dictCodes = this.delarr.join(",");
  327. dataRemove({ dictCodes: dictCodes })
  328. .then(() => {
  329. this.$notify({
  330. title: "成功",
  331. message: "删除成功",
  332. type: "success",
  333. duration: 2000,
  334. });
  335. this.getList();
  336. })
  337. .catch(() => { });
  338. } else {
  339. this.$notify({
  340. title: "警告提示",
  341. message: "请选择要删除的信息!",
  342. type: "warning",
  343. });
  344. }
  345. })
  346. .catch(() => { });
  347. },
  348. handleSelectionChange(val) {
  349. this.multipleSelection = val;
  350. },
  351. }
  352. }
  353. </script>
  354. <style>
  355. .ad-avatar-uploader .el-upload {
  356. border: 1px dashed #d9d9d9;
  357. border-radius: 6px;
  358. cursor: pointer;
  359. position: relative;
  360. overflow: hidden;
  361. }
  362. .ad-avatar-uploader .el-upload:hover {
  363. border-color: #409EFF;
  364. }
  365. .ad-avatar-uploader-icon {
  366. font-size: 28px;
  367. color: #8c939d;
  368. width: 178px;
  369. height: 178px;
  370. line-height: 178px;
  371. text-align: center;
  372. }
  373. .ad-avatar {
  374. display: block;
  375. }
  376. </style>