plm前端
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.

329 lines
9.1 KiB

2 years 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="设置表格栏位"
  4. :visible.sync="visible"
  5. class="cl"
  6. width="958px" v-drag>
  7. <el-select @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="栏位名称">
  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="80"
  28. label="显示顺序">
  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="显示状态">
  36. <template slot-scope="scope">
  37. <el-switch
  38. v-model="scope.row.status"
  39. active-text="显示"
  40. inactive-text="隐藏">
  41. </el-switch>
  42. </template>
  43. </el-table-column>
  44. <el-table-column
  45. width="120"
  46. label="固定位置">
  47. <template slot-scope="scope">
  48. <el-select style="width: 100px" v-model="scope.row.fixed">
  49. <el-option label="不固定" value=""></el-option>
  50. <el-option label="左固定" value="left"></el-option>
  51. <el-option label="右固定" value="right"></el-option>
  52. </el-select>
  53. </template>
  54. </el-table-column>
  55. <el-table-column
  56. width="160"
  57. label="排序">
  58. <template slot-scope="scope">
  59. <el-switch
  60. v-model="scope.row.columnSortable"
  61. active-text="排序"
  62. inactive-text="不排序">
  63. </el-switch>
  64. </template>
  65. </el-table-column>
  66. <el-table-column
  67. width="100"
  68. label="宽度">
  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="类型">
  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="位置">
  87. <template slot-scope="scope">
  88. <el-select v-model="scope.row.align">
  89. <el-option value="left" label="居左"></el-option>
  90. <el-option value="center" label="居中"></el-option>
  91. <el-option value="right" label="居右"></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()">确定</el-button>
  98. <el-button @click="visible = false" type="primary">取消</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. // 展示列集
  114. columnList: [
  115. {
  116. columnLabel: "显示顺序",
  117. columnHidden: false,
  118. columnImage: false,
  119. columnSortable: false,
  120. columnWidth: null,
  121. format: null,
  122. sortLv: 0,
  123. status: true,
  124. fixed: '',
  125. serialNumber: null,
  126. columnType: null,
  127. align: null
  128. },
  129. {
  130. columnLabel: "显示状态",
  131. columnHidden: false,
  132. columnImage: false,
  133. columnSortable: false,
  134. columnWidth: null,
  135. format: null,
  136. sortLv: 0,
  137. status: true,
  138. fixed: '',
  139. serialNumber: null,
  140. columnType: null,
  141. align: null
  142. },
  143. {
  144. columnLabel: "排序",
  145. columnHidden: false,
  146. columnImage: false,
  147. columnSortable: false,
  148. columnWidth: null,
  149. format: null,
  150. sortLv: 0,
  151. status: true,
  152. fixed: '',
  153. serialNumber: null,
  154. columnType: null,
  155. align: null
  156. },
  157. {
  158. columnLabel: "固定状态",
  159. columnHidden: false,
  160. columnImage: false,
  161. columnSortable: false,
  162. columnWidth: null,
  163. format: null,
  164. sortLv: 0,
  165. status: true,
  166. fixed: '',
  167. serialNumber: null,
  168. columnType: null,
  169. align: null
  170. },
  171. {
  172. columnLabel: "宽度",
  173. columnHidden: false,
  174. columnImage: false,
  175. columnSortable: false,
  176. columnWidth: null,
  177. format: null,
  178. sortLv: 0,
  179. status: true,
  180. fixed: '',
  181. serialNumber: null,
  182. columnType: null,
  183. align: null
  184. },
  185. {
  186. columnLabel: "类型",
  187. columnHidden: false,
  188. columnImage: false,
  189. columnSortable: false,
  190. columnWidth: null,
  191. format: null,
  192. sortLv: 0,
  193. status: true,
  194. fixed: '',
  195. serialNumber: null,
  196. columnType: null,
  197. align: null
  198. },
  199. {
  200. columnLabel: "位置",
  201. columnHidden: false,
  202. columnImage: false,
  203. columnSortable: false,
  204. columnWidth: null,
  205. format: null,
  206. sortLv: 0,
  207. status: true,
  208. fixed: '',
  209. serialNumber: null,
  210. columnType: null,
  211. align: null
  212. },
  213. ],
  214. tableList: [],
  215. dataList: [],
  216. dataListLoading: false,
  217. // 用户table 配置集合
  218. userColumnList: [],
  219. queryTable: {
  220. userId: '',
  221. functionId: '',
  222. languageCode: '',
  223. tableId: '',
  224. },
  225. visible: false,
  226. fullscreenLoading: false
  227. }
  228. },
  229. methods: {
  230. // 获取 用户的配置
  231. async init(queryTable) {
  232. if (!queryTable.functionId) return;
  233. this.visible = true
  234. this.queryTable = queryTable
  235. // 先获取功能下的所有tableId 和tableName
  236. await getMenuTableList(queryTable).then(({data}) => {
  237. if (data && data.code == 0) {
  238. this.tableList = data.data
  239. this.queryTable.tableId = data.data.length>0?data.data[0].tableId:'-1'
  240. }
  241. })
  242. await this.getTableUserList()
  243. },
  244. async getTableUserList(){
  245. this.dataListLoading = true
  246. await getTableUserListLanguage(this.queryTable).then(({data}) => {
  247. if (data.code == 0) {
  248. this.dataListLoading = false
  249. this.userColumnList = data.rows
  250. if (data.rows.length <= 0) {
  251. getTableDefaultListLanguage(this.queryTable).then(({data}) => {
  252. this.userColumnList = data.rows
  253. })
  254. }
  255. }
  256. })
  257. },
  258. // 修改 table 列
  259. updateColumnList() {
  260. const loading = this.$loading({
  261. lock: true,
  262. text: '正在保存用户设置',
  263. spinner: 'el-icon-loading',
  264. background: 'rgba(0, 0, 0, 0.7)'
  265. });
  266. let userColumns = []
  267. for (let column of this.userColumnList) {
  268. let userColumn = {
  269. userId: this.$store.state.user.name,
  270. functionId: column.functionId,
  271. tableId: column.tableId,
  272. tableName: column.tableName,
  273. columnProp: column.columnProp,
  274. headerAlign: column.headerAlign,
  275. align: column.align,
  276. columnWidth: column.columnWidth,
  277. columnLabel: column.columnLabel,
  278. columnHidden: column.columnHidden,
  279. columnImage: column.columnImage,
  280. columnSortable: column.columnSortable,
  281. format: column.format,
  282. sortLv: column.sortLv,
  283. status: column.status,
  284. fixed: column.fixed,
  285. serialNumber: column.serialNumber,
  286. columnType: column.columnType
  287. }
  288. userColumns.push(userColumn)
  289. this.$emit("refreshData");
  290. }
  291. saveTableUser(userColumns).then(({data}) => {
  292. if (data.code == 0) {
  293. this.$message.success(data.msg)
  294. loading.close();
  295. this.visible = false
  296. this.$emit("refreshData", this.queryTable.tableId);
  297. } else {
  298. this.$message.error(data.msg)
  299. }
  300. })
  301. },
  302. }
  303. }
  304. </script>
  305. <style>
  306. .cl .el-table .cell {
  307. line-height: 20px;
  308. font-size: 12px;
  309. height: 20px;
  310. }
  311. .cl .el-switch__label * {
  312. line-height: 1;
  313. font-size: 12px;
  314. display: inline-block;
  315. }
  316. </style>