page1.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div id="">
  3. <el-table :data="tableData" style="margin-top: 10px" border>
  4. <el-table-column
  5. v-for="(item, index) in tableSet"
  6. :width="item.width"
  7. :key="index"
  8. :prop="item.prop"
  9. :label="item.label"
  10. align="center"
  11. >
  12. <template slot-scope="scope">
  13. <div v-if="item.scope === 'input'">
  14. <el-input-number
  15. @blur="changeVal(scope.row)"
  16. v-model="scope.row[item.prop]"
  17. :controls="false"
  18. :min="0"
  19. :precision="0"
  20. style="width: 50%"
  21. ></el-input-number>
  22. </div>
  23. <div v-else-if="item.scope === 'inputPath'">
  24. <el-input
  25. v-model="scope.row[item.prop]"
  26. style="width: 50%"
  27. ></el-input>
  28. </div>
  29. <div v-else-if="item.scope === 'status'" class="disflex_sty">
  30. <el-switch
  31. :size="size"
  32. v-if="scope.row['name'] !== '首页'"
  33. :active-value="1"
  34. :inactive-value="0"
  35. v-model="scope.row[item.prop]"
  36. active-color="#13ce66"
  37. inactive-color="#ff4949"
  38. >
  39. </el-switch>
  40. <span style="margin-left: 14px">
  41. {{
  42. scope.row[item.prop] === 1
  43. ? "开启"
  44. : scope.row[item.prop] === 0
  45. ? "关闭"
  46. : "未知"
  47. }}
  48. </span>
  49. </div>
  50. <div v-else>{{ scope.row[item.prop] }}</div>
  51. </template></el-table-column
  52. >
  53. </el-table>
  54. <div style="margin-top: 20px">
  55. <el-button type="primary" @click="submit">保存</el-button>
  56. </div>
  57. </div>
  58. </template>
  59. <script>
  60. import { listConfig, updateConfig } from "@/api/system/config";
  61. export default {
  62. data() {
  63. return {
  64. initData: {
  65. configValue: {},
  66. },
  67. tableData: [],
  68. tableSet: [
  69. {
  70. label: "排序",
  71. prop: "sort",
  72. scope: "input",
  73. },
  74. {
  75. label: "导航菜单名称",
  76. prop: "name",
  77. scope: "inputPath",
  78. },
  79. {
  80. label: "路由地址",
  81. prop: "path",
  82. scope: "inputPath",
  83. },
  84. {
  85. label: "状态",
  86. prop: "status",
  87. scope: "status",
  88. },
  89. ],
  90. };
  91. },
  92. mounted() {
  93. this.init();
  94. },
  95. methods: {
  96. init() {
  97. listConfig({ configKey: "client.config" }).then((res) => {
  98. if (res.rows.length) {
  99. this.initData = res.rows[0];
  100. let configValue = JSON.parse(res.rows[0].configValue) || {};
  101. this.tableData = configValue.nav || [];
  102. }
  103. });
  104. },
  105. changeVal(row) {
  106. if (!row.sort && row.sort !== 0) {
  107. this.$message.warning("检测到你没有赋值或赋值异常,已自动赋值为0");
  108. row.sort = 0;
  109. } else {
  110. for (let i = 0; i < this.tableData.length; i++) {
  111. if (
  112. this.tableData[i].name !== row.name &&
  113. this.tableData[i].sort == row.sort
  114. ) {
  115. this.$message.warning("检测到重复值,已自动赋值为0");
  116. row.sort = 0;
  117. }
  118. }
  119. }
  120. this.tableData.sort(this.sort);
  121. },
  122. submit() {
  123. let initData = JSON.parse(JSON.stringify(this.initData));
  124. initData.configValue = JSON.parse(initData.configValue);
  125. initData.configValue["nav"] = this.tableData;
  126. initData.configValue = JSON.stringify(initData.configValue);
  127. updateConfig(initData).then((res) => {
  128. this.$message.success("保存成功");
  129. this.init();
  130. });
  131. },
  132. },
  133. };
  134. </script>
  135. <style lang="scss" scoped></style>