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.

332 lines
9.2 KiB

6 months ago
  1. <template>
  2. <el-dialog :modal-append-to-body="false"
  3. :close-on-click-modal="false" :show-close="false" :close-on-press-escape="false" :title="titleDesc"
  4. :visible.sync="visible"
  5. class="cl"
  6. width="958px" v-drag>
  7. <el-select v-show="false" @change="getTableUserList()" v-model="queryTable.tableId">
  8. <el-option :value="item.tableId" :label="item.tableName" v-for="(item,index) in tableList" :key="index">
  9. </el-option>
  10. </el-select>
  11. <el-table
  12. :height="height"
  13. :data="userColumnList"
  14. border
  15. v-loading="dataListLoading"
  16. highlight-current-row
  17. :row-style="{height: '20px'}"
  18. style="width: 100%;">
  19. <el-table-column
  20. width="120"
  21. label="Field Caption">
  22. <template slot-scope="scope">
  23. <el-input readonly v-model="scope.row.columnLabel"></el-input>
  24. </template>
  25. </el-table-column>
  26. <el-table-column
  27. width="100"
  28. label="Display Seq">
  29. <template slot-scope="scope">
  30. <el-input oninput="value=value.replace(/[^\d]/g, '')" v-model="scope.row.sortLv" :min="0"></el-input>
  31. </template>
  32. </el-table-column>
  33. <el-table-column
  34. width="140"
  35. label="Display State">
  36. <template slot-scope="scope">
  37. <el-switch
  38. v-model="scope.row.status"
  39. active-text="Show"
  40. inactive-text="Hide">
  41. </el-switch>
  42. </template>
  43. </el-table-column>
  44. <el-table-column
  45. width="120"
  46. label="Freeze Column">
  47. <template slot-scope="scope">
  48. <el-select style="width: 100px" v-model="scope.row.fixed">
  49. <el-option label="Not Fixed" value=""></el-option>
  50. <el-option label="Left Fixed" value="left"></el-option>
  51. <el-option label="Right Fixed" value="right"></el-option>
  52. </el-select>
  53. </template>
  54. </el-table-column>
  55. <el-table-column
  56. width="160"
  57. label="Sort">
  58. <template slot-scope="scope">
  59. <el-switch
  60. v-model="scope.row.columnSortable"
  61. active-text="Sort"
  62. inactive-text="Not Sorted">
  63. </el-switch>
  64. </template>
  65. </el-table-column>
  66. <el-table-column
  67. width="100"
  68. label="Column Width">
  69. <template slot-scope="scope">
  70. <el-input oninput="value=value.replace(/[^\d]/g, '')" v-model="scope.row.columnWidth" :min="0"></el-input>
  71. </template>
  72. </el-table-column>
  73. <!-- <el-table-column
  74. width="100"
  75. label="Type">
  76. <template slot-scope="scope">
  77. <el-select v-model="scope.row.columnType">
  78. <el-option value="string" label="string"></el-option>
  79. <el-option value="number" label="number"></el-option>
  80. <el-option value="date" label="date"></el-option>
  81. </el-select>
  82. </template>
  83. </el-table-column>-->
  84. <el-table-column
  85. width="100"
  86. label="Align">
  87. <template slot-scope="scope">
  88. <el-select v-model="scope.row.align">
  89. <el-option value="left" label="Left"></el-option>
  90. <el-option value="center" label="Center"></el-option>
  91. <el-option value="right" label="Right"></el-option>
  92. </el-select>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <span slot="footer" class="dialog-footer">
  97. <el-button type="primary" @click="updateColumnList()">Save</el-button>
  98. <el-button @click="visible = false" type="primary">Close</el-button>
  99. </span>
  100. </el-dialog>
  101. </template>
  102. <script>
  103. import {
  104. saveTableUser,
  105. getTableDefaultListLanguage,
  106. getTableUserListLanguage,
  107. getMenuTableList
  108. } from "@/api/table.js"
  109. export default {
  110. data() {
  111. return {
  112. height: 400,
  113. titleDesc: 'Set Table Fields',
  114. // 展示列集
  115. columnList: [
  116. {
  117. columnLabel: "显示顺序",
  118. columnHidden: false,
  119. columnImage: false,
  120. columnSortable: false,
  121. columnWidth: null,
  122. format: null,
  123. sortLv: 0,
  124. status: true,
  125. fixed: '',
  126. serialNumber: null,
  127. columnType: null,
  128. align: null
  129. },
  130. {
  131. columnLabel: "显示状态",
  132. columnHidden: false,
  133. columnImage: false,
  134. columnSortable: false,
  135. columnWidth: null,
  136. format: null,
  137. sortLv: 0,
  138. status: true,
  139. fixed: '',
  140. serialNumber: null,
  141. columnType: null,
  142. align: null
  143. },
  144. {
  145. columnLabel: "排序",
  146. columnHidden: false,
  147. columnImage: false,
  148. columnSortable: false,
  149. columnWidth: null,
  150. format: null,
  151. sortLv: 0,
  152. status: true,
  153. fixed: '',
  154. serialNumber: null,
  155. columnType: null,
  156. align: null
  157. },
  158. {
  159. columnLabel: "固定状态",
  160. columnHidden: false,
  161. columnImage: false,
  162. columnSortable: false,
  163. columnWidth: null,
  164. format: null,
  165. sortLv: 0,
  166. status: true,
  167. fixed: '',
  168. serialNumber: null,
  169. columnType: null,
  170. align: null
  171. },
  172. {
  173. columnLabel: "宽度",
  174. columnHidden: false,
  175. columnImage: false,
  176. columnSortable: false,
  177. columnWidth: null,
  178. format: null,
  179. sortLv: 0,
  180. status: true,
  181. fixed: '',
  182. serialNumber: null,
  183. columnType: null,
  184. align: null
  185. },
  186. {
  187. columnLabel: "类型",
  188. columnHidden: false,
  189. columnImage: false,
  190. columnSortable: false,
  191. columnWidth: null,
  192. format: null,
  193. sortLv: 0,
  194. status: true,
  195. fixed: '',
  196. serialNumber: null,
  197. columnType: null,
  198. align: null
  199. },
  200. {
  201. columnLabel: "位置",
  202. columnHidden: false,
  203. columnImage: false,
  204. columnSortable: false,
  205. columnWidth: null,
  206. format: null,
  207. sortLv: 0,
  208. status: true,
  209. fixed: '',
  210. serialNumber: null,
  211. columnType: null,
  212. align: null
  213. },
  214. ],
  215. tableList: [],
  216. dataList: [],
  217. dataListLoading: false,
  218. // 用户table 配置集合
  219. userColumnList: [],
  220. queryTable: {
  221. userId: '',
  222. functionId: '',
  223. languageCode: '',
  224. tableId: '',
  225. },
  226. visible: false,
  227. fullscreenLoading: false
  228. }
  229. },
  230. methods: {
  231. // 获取 用户的配置
  232. async init(queryTable) {
  233. if (!queryTable.functionId) return;
  234. this.visible = true
  235. this.queryTable = queryTable
  236. // 先获取功能下的所有tableId 和tableName
  237. await getMenuTableList(queryTable).then(({data}) => {
  238. if (data && data.code == 0) {
  239. this.tableList = data.data
  240. this.queryTable.tableId = data.data.length>0?data.data[0].tableId:'-1'
  241. }
  242. })
  243. await this.getTableUserList()
  244. },
  245. async getTableUserList(){
  246. this.dataListLoading = true
  247. await getTableUserListLanguage(this.queryTable).then(({data}) => {
  248. if (data.code == 0) {
  249. this.dataListLoading = false
  250. this.userColumnList = data.rows
  251. if (data.rows.length <= 0) {
  252. getTableDefaultListLanguage(this.queryTable).then(({data}) => {
  253. this.userColumnList = data.rows;
  254. //设置标题
  255. this.titleDesc = 'Set Table Fields --'+ data.menuName;
  256. })
  257. }
  258. }
  259. })
  260. },
  261. // 修改 table 列
  262. updateColumnList() {
  263. const loading = this.$loading({
  264. lock: true,
  265. text: '正在保存用户设置',
  266. spinner: 'el-icon-loading',
  267. background: 'rgba(0, 0, 0, 0.7)'
  268. });
  269. let userColumns = []
  270. for (let column of this.userColumnList) {
  271. let userColumn = {
  272. userId: this.$store.state.user.name,
  273. functionId: column.functionId,
  274. tableId: column.tableId,
  275. tableName: column.tableName,
  276. columnProp: column.columnProp,
  277. headerAlign: column.headerAlign,
  278. align: column.align,
  279. columnWidth: column.columnWidth,
  280. columnLabel: column.columnLabel,
  281. columnHidden: column.columnHidden,
  282. columnImage: column.columnImage,
  283. columnSortable: column.columnSortable,
  284. format: column.format,
  285. sortLv: column.sortLv,
  286. status: column.status,
  287. fixed: column.fixed,
  288. serialNumber: column.serialNumber,
  289. columnType: column.columnType
  290. }
  291. userColumns.push(userColumn)
  292. this.$emit("refreshData");
  293. }
  294. saveTableUser(userColumns).then(({data}) => {
  295. if (data.code == 0) {
  296. this.$message.success(data.msg)
  297. loading.close();
  298. this.visible = false
  299. this.$emit("refreshData", this.queryTable.tableId);
  300. } else {
  301. this.$message.error(data.msg)
  302. }
  303. })
  304. },
  305. }
  306. }
  307. </script>
  308. <style>
  309. .cl .el-table .cell {
  310. line-height: 20px;
  311. font-size: 12px;
  312. height: 20px;
  313. }
  314. .cl .el-switch__label * {
  315. line-height: 1;
  316. font-size: 12px;
  317. display: inline-block;
  318. }
  319. </style>