index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div className="app-container">
  3. <div className="xTable">
  4. <vxe-grid ref='xGrid' v-bind="gridOptions"></vxe-grid>
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. gridOptions: {
  13. border: true,
  14. resizable: true,
  15. showHeaderOverflow: true,
  16. showOverflow: true,
  17. highlightHoverRow: true,
  18. keepSource: true,
  19. id: 'full_edit_1',
  20. height: 600,
  21. rowId: 'id',
  22. customConfig: {
  23. storage: true,
  24. checkMethod: this.checkColumnMethod
  25. },
  26. printConfig: {
  27. columns: [
  28. {field: 'name'},
  29. {field: 'email'},
  30. {field: 'nickname'},
  31. {field: 'age'},
  32. {field: 'amount'}
  33. ]
  34. },
  35. sortConfig: {
  36. trigger: 'cell',
  37. remote: true
  38. },
  39. filterConfig: {
  40. remote: true
  41. },
  42. pagerConfig: {
  43. pageSize: 10,
  44. pageSizes: [5, 10, 15, 20, 50, 100, 200, 500, 1000]
  45. },
  46. formConfig: {
  47. titleWidth: 100,
  48. titleAlign: 'right',
  49. items: [
  50. {
  51. field: 'name',
  52. title: '风机编号',
  53. span: 8,
  54. titlePrefix: {message: 'app.body.valid.rName', icon: 'fa fa-exclamation-circle'},
  55. itemRender: {name: '$input', props: {placeholder: '请输入风机编号'}}
  56. },
  57. {field: 'wind', title: '风向', span: 8, itemRender: {name: '$select', options: [
  58. {}
  59. ]}},
  60. {field: 'speed', title: '风速', span: 8, itemRender: {name: '$input', props: {placeholder: '请输入风速'}}},
  61. {
  62. field: 'unitBelong',
  63. title: '所属机组',
  64. span: 8,
  65. itemRender: {name: '$input', props: {placeholder: '请输入所属机组'}}
  66. },
  67. {field: 'belong', title: '所属行', span: 8, itemRender: {name: '$input', props: {placeholder: '请输入所属行'}}},
  68. // { field: 'unitBelong', title: '所属机组', span: 8, folding: true, itemRender: { name: '$input', props: { placeholder: '请输入所属机组' } } },
  69. // { field: 'belong', title: '所属行', span: 8, folding: true, titleSuffix: { message: '注意,必填信息!', icon: 'fa fa-info-circle' }, itemRender: { name: '$select', options: [] } },
  70. // { field: 'age', title: '年龄', span: 8, folding: true, itemRender: { name: '$input', props: { type: 'number', min: 1, max: 120, placeholder: '请输入年龄' } } },
  71. {
  72. span: 24,
  73. align: 'center',
  74. itemRender: {
  75. name: '$buttons',
  76. children: [{props: {type: 'submit', content: '提交', status: 'primary'}}, {
  77. props: {
  78. type: 'reset',
  79. content: '重置'
  80. }
  81. }]
  82. }
  83. }
  84. ]
  85. },
  86. toolbarConfig: {
  87. buttons: [
  88. {code: 'insert_actived', name: '新增', icon: 'fa fa-plus'},
  89. {code: 'delete', name: '直接删除', icon: 'fa fa-trash-o'},
  90. {code: 'mark_cancel', name: '删除/取消', icon: 'fa fa-trash-o'},
  91. {code: 'save', name: '保存', icon: 'fa fa-save', status: 'success'}
  92. ],
  93. refresh: true,
  94. import: true,
  95. export: true,
  96. print: true,
  97. zoom: true,
  98. custom: true
  99. },
  100. proxyConfig: {
  101. seq: true, // 启用动态序号代理
  102. sort: true, // 启用排序代理
  103. filter: true, // 启用筛选代理
  104. form: true, // 启用表单代理
  105. props: {
  106. result: 'result',
  107. total: 'page.total'
  108. },
  109. ajax: {
  110. // // 接收 Promise 对象
  111. // query: ({ page, sorts, filters, form }) => {
  112. // const queryParams = Object.assign({}, form)
  113. // // 处理排序条件
  114. // const firstSort = sorts[0]
  115. // if (firstSort) {
  116. // queryParams.sort = firstSort.property
  117. // queryParams.order = firstSort.order
  118. // }
  119. // // 处理筛选条件
  120. // filters.forEach(({ property, values }) => {
  121. // queryParams[property] = values.join(',')
  122. // })
  123. // return XEAjax.get(`${this.serveApiUrl}/api/pub/page/list/${page.pageSize}/${page.currentPage}`, queryParams)
  124. // },
  125. delete: ({body}) => XEAjax.post(`${this.serveApiUrl}/api/pub/save`, body),
  126. save: ({body}) => XEAjax.post(`${this.serveApiUrl}/api/pub/save`, body)
  127. }
  128. },
  129. columns: [
  130. {type: 'checkbox', title: 'ID', width: 120},
  131. {field: 'id', title: 'ID', sortable: true, editRender: {name: 'input'}},
  132. {field: 'fanNumber', title: '风机编号', sortable: true, editRender: {name: 'input'}},
  133. {field: 'wind', title: '风向', sortable: true, editRender: {name: 'input'}},
  134. {field: 'speed', title: '风速', sortable: true, editRender: {name: 'input'}},
  135. {field: 'unitBelongs', title: '所属机组', sortable: true, editRender: {name: 'input'}},
  136. {field: 'belong', title: '所属行', sortable: true, editRender: {name: 'input'}},
  137. ],
  138. importConfig: {
  139. remote: true,
  140. importMethod: this.importMethod,
  141. types: ['xlsx'],
  142. modes: ['insert']
  143. },
  144. exportConfig: {
  145. remote: true,
  146. exportMethod: this.exportMethod,
  147. types: ['xlsx'],
  148. modes: ['current', 'selected', 'all']
  149. },
  150. checkboxConfig: {
  151. labelField: 'id',
  152. reserve: true,
  153. highlight: true,
  154. range: true
  155. },
  156. editRules: {},
  157. editConfig: {
  158. trigger: 'click',
  159. mode: 'row',
  160. showStatus: true
  161. }
  162. }
  163. }
  164. },
  165. computed: {
  166. // ...mapState([
  167. // 'serveApiUrl'
  168. // ])
  169. },
  170. created() {
  171. this.findSexList()
  172. },
  173. methods: {
  174. async findSexList() {
  175. // const sexList = await XEAjax.get('/api/conf/sex/list')
  176. // // 异步更新下拉选项
  177. // this.sexList = sexList
  178. // const xGrid = this.$refs.xGrid
  179. // if (xGrid) {
  180. // const sexColumn = xGrid.getColumnByField('sex')
  181. // sexColumn.editRender.options = sexList
  182. // const sexItem = xGrid.getFormItems(4)
  183. // sexItem.itemRender.options = sexList
  184. // }
  185. },
  186. formatAmount({cellValue}) {
  187. // return cellValue ? `$${XEUtils.commafy(XEUtils.toNumber(cellValue), { digits: 2 })}` : ''
  188. },
  189. formatDate({cellValue}) {
  190. // return XEUtils.toDateString(cellValue, 'yyyy-MM-dd HH:ss:mm')
  191. },
  192. checkColumnMethod({column}) {
  193. // if (['nickname', 'role'].includes(column.property)) {
  194. // return false
  195. // }
  196. // return true
  197. },
  198. importMethod({file}) {
  199. // const formBody = new FormData()
  200. // formBody.append('file', file)
  201. // return XEAjax.post(`${this.serveApiUrl}/api/pub/import`, formBody).then(data => {
  202. // this.$XModal.message({ message: `成功导入 ${data.result.insertRows} 条记录!`, status: 'success' })
  203. // // 导入完成,刷新表格
  204. // this.$refs.xGrid.commitProxy('query')
  205. // }).catch(() => {
  206. // this.$XModal.message({ message: '导入失败,请检查数据是否正确!', status: 'error' })
  207. // })
  208. },
  209. exportMethod({options}) {
  210. // const proxyInfo = this.$refs.xGrid.getProxyInfo()
  211. // // 传给服务端的参数
  212. // const body = {
  213. // filename: options.filename,
  214. // sheetName: options.sheetName,
  215. // isHeader: options.isHeader,
  216. // original: options.original,
  217. // mode: options.mode,
  218. // pager: proxyInfo.pager,
  219. // ids: options.mode === 'selected' ? options.data.map(item => item.id) : [],
  220. // fields: options.columns.map(column => {
  221. // return {
  222. // field: column.property,
  223. // title: column.title
  224. // }
  225. // })
  226. // }
  227. // // 开始服务端导出
  228. // return XEAjax.post(`${this.serveApiUrl}/api/pub/export`, body).then(data => {
  229. // if (data.id) {
  230. // this.$XModal.message({ message: '导出成功,开始下载', status: 'success' })
  231. // // 读取路径,请求文件流 => 开始下载
  232. // location.href = `${this.serveApiUrl}/api/pub/export/download/${data.id}`
  233. // }
  234. // }).catch(() => {
  235. // this.$XModal.message({ message: '导出失败!', status: 'error' })
  236. // })
  237. }
  238. }
  239. }
  240. </script>
  241. <style scoped>
  242. </style>