data.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <!--配置字典-->
  2. <template>
  3. <div class="page-container dictAddPage">
  4. <div class="page-form-title-box">
  5. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" class="form-box">
  6. <el-form-item label="" prop="label">
  7. <el-input
  8. v-model="queryParams.label"
  9. placeholder="请输入字典标签"
  10. clearable
  11. size="small"
  12. />
  13. </el-form-item>
  14. <el-form-item label="" prop="state">
  15. <el-select v-model="queryParams.state" placeholder="请选择状态" clearable size="small">
  16. <el-option
  17. v-for="dict in statusOptions"
  18. :key="dict.dictValue"
  19. :label="dict.dictLabel"
  20. :value="dict.dictValue"
  21. />
  22. </el-select>
  23. </el-form-item>
  24. <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
  25. <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
  26. <p class="page-out-common-style-button"
  27. style="float: right;"
  28. @click="backPage"
  29. >返回</p>
  30. <p class="page-submit-common-style-button"
  31. style="float: right;margin-right:20px;"
  32. @click="handleAdd"
  33. v-hasPermiRouter="['system:dict:add']"
  34. >新增</p>
  35. </el-form>
  36. </div>
  37. <div class="page-content-box">
  38. <el-table class="table-box" v-loading="loading" border :data="dataList" @selection-change="handleSelectionChange">
  39. <el-table-column label="字典名称" align="left" prop="label"/>
  40. <el-table-column label="字典数值" align="left" prop="value" />
  41. <el-table-column label="显示顺序" align="left" prop="sort" />
  42. <el-table-column label="状态" align="left" prop="state" v-hasPermiRouter="['system:dict:edit']">
  43. <template slot-scope="scope">
  44. <el-switch
  45. class="switch captcha-img"
  46. @change="switchChange(scope.row)"
  47. v-model="scope.row.state"
  48. :active-value="true"
  49. :inactive-value="false"
  50. active-text="开"
  51. inactive-text="关"
  52. >
  53. </el-switch>
  54. <!--<dict-tag :options="statusOptions" :value="scope.row.state"/>-->
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="备注" align="left" prop="remark" :show-overflow-tooltip="true" />
  58. <el-table-column label="创建时间" align="left" prop="createTime" width="180">
  59. <template slot-scope="scope">
  60. <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}:{s}") }}</span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="操作" align="left"
  64. class-name="small-padding fixed-width" width="160"
  65. v-if="tableButtonType">
  66. <template slot-scope="scope">
  67. <div class="table-button-box">
  68. <p class="table-button-null"></p>
  69. <p class="table-button-p"
  70. @click="handleUpdate(scope.row)"
  71. v-hasPermiRouter="['system:dict:edit']"
  72. >编辑</p>
  73. <p class="table-button-p"
  74. @click="handleDelete(scope.row)"
  75. v-hasPermiRouter="['system:dict:del']"
  76. >删除</p>
  77. <p class="table-button-null"></p>
  78. </div>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <pagination :page-sizes="[20, 30, 40, 50]"
  83. v-show="total>0"
  84. :total="total"
  85. layout="total, prev, pager, next, sizes, jumper"
  86. :page.sync="queryParams.page"
  87. :limit.sync="queryParams.pageSize"
  88. @pagination="getList"
  89. />
  90. </div>
  91. <!-- 添加或修改参数配置对话框 -->
  92. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body :close-on-click-modal="false">
  93. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  94. <el-form-item label="数据标签" prop="label">
  95. <el-input v-model="form.label" placeholder="请输入数据标签" />
  96. </el-form-item>
  97. <el-form-item label="数据键值" prop="value">
  98. <el-input v-model="form.value" placeholder="请输入数据键值" />
  99. </el-form-item>
  100. <el-form-item label="显示排序" prop="sort">
  101. <el-input-number v-model="form.sort" controls-position="right" :min="0" />
  102. </el-form-item>
  103. <el-form-item label="状态" prop="state">
  104. <el-radio-group v-model="form.state">
  105. <el-radio
  106. v-for="dict in statusOptions"
  107. :key="dict.dictValue"
  108. :label="dict.dictValue"
  109. >{{dict.dictLabel}}</el-radio>
  110. </el-radio-group>
  111. </el-form-item>
  112. <el-form-item label="备注" prop="remark">
  113. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  114. </el-form-item>
  115. </el-form>
  116. <div slot="footer" class="dialog-footer dialog-footer-box">
  117. <p class="dialog-footer-button-null"></p>
  118. <p class="dialog-footer-button-info" @click="cancel">取消</p>
  119. <p class="dialog-footer-button-primary" @click="submitForm">确定</p>
  120. <p class="dialog-footer-button-null"></p>
  121. </div>
  122. </el-dialog>
  123. </div>
  124. </template>
  125. <script>
  126. import { listData, getData, delData, addData, updateData,listType, getType } from "@/api/systemManagement/index";
  127. export default {
  128. props: {
  129. dictId: {},
  130. },
  131. name: "Data",
  132. data() {
  133. return {
  134. tableButtonType:this.hasPermiDom(['system:dict:edit','system:dict:detail','system:dict:del']),
  135. // 遮罩层
  136. loading: true,
  137. // 选中数组
  138. ids: [],
  139. // 非单个禁用
  140. single: true,
  141. // 非多个禁用
  142. multiple: true,
  143. // 显示搜索条件
  144. showSearch: true,
  145. // 总条数
  146. total: 0,
  147. // 字典表格数据
  148. dataList: [],
  149. // 默认字典类型
  150. defaultDictType: "",
  151. // 弹出层标题
  152. title: "",
  153. // 是否显示弹出层
  154. open: false,
  155. // 数据标签回显样式
  156. listClassOptions: [
  157. {
  158. value: "default",
  159. label: "默认"
  160. },
  161. {
  162. value: "primary",
  163. label: "主要"
  164. },
  165. {
  166. value: "success",
  167. label: "成功"
  168. },
  169. {
  170. value: "info",
  171. label: "信息"
  172. },
  173. {
  174. value: "warning",
  175. label: "警告"
  176. },
  177. {
  178. value: "danger",
  179. label: "危险"
  180. }
  181. ],
  182. // 状态数据字典
  183. statusOptions: [
  184. { dictValue:true,dictLabel:"开" },
  185. { dictValue:false,dictLabel:"关" },
  186. ],
  187. // 类型数据字典
  188. typeOptions: [],
  189. // 日期范围
  190. dateRange: [],
  191. // 查询参数
  192. queryParams: {
  193. page: 1,
  194. pageSize:20,
  195. dictName: undefined,
  196. dictId: undefined,
  197. state: undefined
  198. },
  199. // 表单参数
  200. form: {},
  201. // 表单校验
  202. rules: {
  203. label: [
  204. { required: true, message: "数据标签不能为空", trigger: "blur" },
  205. { required: true, message: "数据标签不能为空", validator: this.spaceJudgment, trigger: "blur" }
  206. ],
  207. value: [
  208. { required: true, message: "数据键值不能为空", trigger: "blur" },
  209. { required: true, message: "数据键值不能为空", validator: this.spaceJudgment, trigger: "blur" }
  210. ],
  211. sort: [
  212. { required: true, message: "数据顺序不能为空", trigger: "blur" },
  213. { required: true, message: "数据顺序不能为空", validator: this.spaceJudgment, trigger: "blur" }
  214. ]
  215. }
  216. };
  217. },
  218. created() {
  219. console.log("dictId",this.dictId)
  220. // const dictId = this.$route.params && this.$route.params.dictId;
  221. const dictId = this.dictId;
  222. this.getType(dictId);
  223. // this.getTypeList();
  224. },
  225. methods: {
  226. //switch开关切换
  227. switchChange(row){
  228. console.log(row);
  229. let obj = JSON.parse(JSON.stringify(row))
  230. obj.dictId = this.dictId;
  231. obj.state = obj.state?obj.state:false
  232. updateData(obj).then(response => {
  233. this.msgSuccess("操作成功");
  234. this.getList();
  235. });
  236. },
  237. //返回按钮
  238. backPage(){
  239. this.$parent.clickPage(1);
  240. },
  241. /** 查询字典类型详细 */
  242. getType(dictId) {
  243. getType({dictId:dictId}).then(response => {
  244. this.defaultDictType = response.data.dictCode;
  245. this.getList();
  246. });
  247. },
  248. /** 查询字典类型列表 */
  249. getTypeList() {
  250. listType().then(response => {
  251. this.typeOptions = response.data.records;
  252. });
  253. },
  254. /** 查询字典数据列表 */
  255. getList() {
  256. this.loading = true;
  257. let obj = JSON.parse(JSON.stringify(this.queryParams))
  258. obj.dictId = this.dictId
  259. listData(obj).then(response => {
  260. this.dataList = response.data.records;
  261. this.total = response.data.total;
  262. this.loading = false;
  263. });
  264. },
  265. // 取消按钮
  266. cancel() {
  267. this.open = false;
  268. this.reset();
  269. },
  270. // 表单重置
  271. reset() {
  272. this.form = {
  273. label: null,
  274. value: null,
  275. sort: 0,
  276. state: true,
  277. remark: undefined
  278. };
  279. this.resetForm("form");
  280. },
  281. /** 搜索按钮操作 */
  282. handleQuery() {
  283. this.queryParams.page = 1;
  284. this.getList();
  285. },
  286. /** 重置按钮操作 */
  287. resetQuery() {
  288. this.dateRange = [];
  289. this.$set(this,'queryParams',{
  290. page: 1,
  291. pageSize:20,
  292. label: null,
  293. state: null
  294. })
  295. this.handleQuery();
  296. },
  297. /** 新增按钮操作 */
  298. handleAdd() {
  299. this.reset();
  300. this.open = true;
  301. this.title = "添加字典数据";
  302. this.form.dictCode = this.queryParams.dictCode;
  303. },
  304. // 多选框选中数据
  305. handleSelectionChange(selection) {
  306. this.ids = selection.map(item => item.dictCode)
  307. this.single = selection.length!=1
  308. this.multiple = !selection.length
  309. },
  310. /** 修改按钮操作 */
  311. handleUpdate(row) {
  312. console.log(row)
  313. this.$set(this,'form',{
  314. itemId:row.itemId,
  315. label:row.label,
  316. value:row.value,
  317. sort:row.sort,
  318. state:row.state,
  319. remark:row.remark,
  320. });
  321. this.open = true;
  322. // this.reset();
  323. // getData({itemId:row.dictId}).then(response => {
  324. // this.form = response.data;
  325. // this.open = true;
  326. // this.title = "修改字典数据";
  327. // });
  328. },
  329. /** 提交按钮 */
  330. submitForm: function() {
  331. this.$refs["form"].validate(valid => {
  332. if (valid) {
  333. let obj = JSON.parse(JSON.stringify(this.form))
  334. obj.dictId = this.dictId;
  335. if (this.form.itemId) {
  336. updateData(obj).then(response => {
  337. this.msgSuccess("修改成功");
  338. this.open = false;
  339. this.getList();
  340. });
  341. } else {
  342. addData(obj).then(response => {
  343. this.msgSuccess("新增成功");
  344. this.open = false;
  345. this.getList();
  346. });
  347. }
  348. }
  349. });
  350. },
  351. /** 删除按钮操作 */
  352. handleDelete(row) {
  353. this.$confirm('是否确认删除该标签?', "警告", {
  354. confirmButtonText: "确定",
  355. cancelButtonText: "取消",
  356. type: "warning"
  357. }).then(function() {
  358. return delData({dictId:row.dictId,itemId:row.itemId});
  359. }).then(() => {
  360. this.getList();
  361. this.msgSuccess("删除成功");
  362. }).catch(() => {});
  363. },
  364. /** 导出按钮操作 */
  365. handleExport() {
  366. this.download('system/dict/data/export', {
  367. ...this.queryParams
  368. }, `data_${new Date().getTime()}.xlsx`)
  369. }
  370. }
  371. };
  372. </script>
  373. <style scoped lang="scss">
  374. .dictAddPage {
  375. }
  376. </style>