tablelet.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. <template>
  2. <div :style="pageTableHeight" class="TablePage">
  3. <PublicPageHeader class="TablePage_header" :page-title="dataTitle ? dataTitle : pageTitle">
  4. <template slot="d_foot">
  5. <SimpleQuery v-if="simpleQueryFlag" :selectOptions="advancedQueryValue" :simple-query-item="simpleQueryItem" @queryValue="queryValue" />
  6. </template>
  7. <template v-if="pageAuthBtnInstall">
  8. <el-button size="small" type="primary" @click="onInstall">初始化</el-button>
  9. </template>
  10. <AuthButton :auth="pageAuthBtnAdd" />
  11. <AuthButton :auth="pageAuthBtnQuery" />
  12. <AuthButton :auth="pageAuthBtnExport" />
  13. </PublicPageHeader>
  14. <div :style="pageTableContentHeight" class="TablePage_content flex-wrap">
  15. <template v-if="!dataFlag">
  16. <div v-if="treeData.length" class="TablePage_content_left">
  17. <PublicPageTree ref="pageTree" :tree-data="treeData" :dep-math="depMath" :tree-map="treeNodeMap" @treeNodeClick="treeNodeClick" />
  18. </div>
  19. </template>
  20. <div :class="dataFlag ? 'tableAuto' : treeData.length ? 'tableSacle' : 'tableAuto'" class="TablePage_content_right">
  21. <PublicPageTable ref="table" :loading="loading" :selected="selected" :table-cols="tableCols" :table-btns="authBtns" :data="tableData" :header-cell-class-name="headerCellClass" :row-class-name="rowClass" :cell-class-name="cellClass" :formatter="tableFormatter" :selectedDatas="selectedDatas" :selectedCheck="selectedDataCheck" :show-summary="summaryFlag" @mounted="tableMountedHandler" @load="load" @cell-click="cellClickHandler" @handleDetail="handleDetail" @handleEdit="handleEdit" @handleOther="handleOther" @handleRemove="handleRemove" @handleSelectionChange="handleSelectionChange" />
  22. </div>
  23. </div>
  24. <div class="TablePage_dialog">
  25. <!--新增/编辑-->
  26. <PublicPageDialog :dialog-body="authId ? true : false " :dialog-loading="dialogLoading" :dialog-title="tableTitle" dialogSize="630px" :form-auth="formAuth" :dialog-drawer="flag" @handleClose="submitClickClose('ruleForm')" @handleSubmit="submitClickHandler">
  27. <PublicPageForm ref="ruleForm" :label-width="labelWidth" :form-pass="tableData" :form-type="tableType" :form-item="formItem" :form-data="tableForm" />
  28. </PublicPageDialog>
  29. <!--高级查询-->
  30. <PublicPageDialog dialog-title="高级查询" dialogSize="600px" :dialog-drawer="advancedDrawer" @handleClose="advancedClose" @handleSubmit="advancedTable('advancedDialogForm')">
  31. <AdvancedQuery ref="advancedDialogForm" :selectOptions="simpleQueryValue" @getAdvancedQueryData="getAdvancedQueryData" />
  32. <template slot="d_foot">
  33. <el-button size="small" @click="restCollect('advancedDialogForm')" type="warning">重置</el-button>
  34. <el-button size="small" @click="queryCollect('advancedDialogForm')" type="primary">收藏</el-button>
  35. </template>
  36. </PublicPageDialog>
  37. <!--初始化-->
  38. <PublicPageDialog dialog-title="初始化" dialogSize="600px" :dialog-drawer="installFlag" @handleClose="installClose" @handleSubmit="installTable('installForm')">
  39. <AuthInstall ref="installForm" />
  40. </PublicPageDialog>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. import PublicPageHeader from '@/components/PublicPageHeader'
  46. import PublicPageTable from '@/components/SimpleTable'
  47. import PublicPageTree from '@/components/publicPageTree'
  48. import PublicPageDialog from '@/components/PublicPageDialog'
  49. import PublicPageForm from '@/components/publicPageForm'
  50. import AdvancedQuery from '@/components/AdvancedQuery'
  51. import AuthButton from '@/components/AuthButton'
  52. import AuthInstall from '@/components/AuthInstall'
  53. import SimpleQuery from '@/components/SimpleQuery'
  54. import { mapGetters } from 'vuex'
  55. import { Query, newData, modifyData, moveData, start, stop, startAll, stopAll } from "@/api/webApi"
  56. import { formatChange, listToTree } from '@/utils/validate'
  57. import { exportToExcel } from '@/utils/table'
  58. export default {
  59. name: 'TablePage',
  60. components: { PublicPageHeader, PublicPageTable, PublicPageDialog, PublicPageTree, PublicPageForm, AdvancedQuery, AuthButton, SimpleQuery, AuthInstall },
  61. props: {
  62. dataTitle: {
  63. type: String,
  64. default: ''
  65. },
  66. dataFlag: {
  67. type: Boolean,
  68. default: false
  69. },
  70. msgContent: {
  71. type: Object,
  72. default: () => new Object()
  73. },
  74. authId: {
  75. type: Number,
  76. default: 0
  77. },
  78. authQuery: {
  79. type: Object,
  80. default: () => new Object()
  81. },
  82. routerlist:{
  83. type: Object,
  84. default: () => new Object()
  85. },
  86. },
  87. data () {
  88. return {
  89. page: 0, //当前table页面
  90. noMore: false, //当前table是否加载到最后开关
  91. loading: false, //页面加载
  92. dialogLoading: false, //新增/编辑确认按钮禁用
  93. advancedDrawer: false, //高级查询弹框开关
  94. defaultfilter: { 1: 1 }, //默认查询参数
  95. pageQuery: {},
  96. installFlag: false,
  97. dialogFlag: false,
  98. dialogName: '', //弹框名称
  99. pageTitle: '', //页面名称
  100. treeData: [], //tree数据
  101. treeParameters: {}, //tree传递参数
  102. treeNodeMap: {}, //tree传递map
  103. tableCols: [], //表头数据
  104. tableData: [], //表格数据
  105. tableBtns: [], //表格按钮权限
  106. authBtns: [], //表格里面的操作按钮
  107. tableBtnForms: [], //表格按钮下的form表单权限
  108. dataContent: {}, //表格查询数据
  109. pageServiceId: null, //表格serviceid
  110. formItem: [], //弹框表单渲染数据
  111. flag: false, //弹框表单开关
  112. formAuth: true, //弹框表单按钮开关
  113. tableType: "add", //弹框表单弹框类型
  114. tableTitle: "新增", //弹框表单标题
  115. tableForm: {}, //弹框表单数据
  116. rmFlag: false, //删除弹框开关
  117. rmTitle: '', //删除弹框标题
  118. tableObj: {}, //删除数据
  119. tableOptions: {}, //表单数据下拉
  120. labelWidth: '120px', //表单文字距离
  121. fromDataReqCatch: [], //表单规则缓存
  122. tableKey: null,//表格主键
  123. depMath: 0,
  124. selected: 0, //是否勾选
  125. selectedDatas: [], //回显勾选的数据
  126. selectedDatasCath: [],//回显数据缓存
  127. selectedDataAlls: [], //勾选数据
  128. selectedDataCheck: {}, //勾选树-选中
  129. triggerserviceid: null, //勾选后查询的serviceid
  130. summaryFlag: false, //是否显示合计行
  131. simpleQueryFlag: false, //是否开启了简易查询
  132. simpleQueryItem: [], //简易查询表单数据项
  133. simpleQueryValue: [], //简易查询缓存值
  134. advancedQueryValue: [], //高级查询缓存值
  135. pageSizeDatas: ['outairportpage', 'landairportpage', 'transairportpage'],
  136. pageInstall: 'permissionsManagementPage'
  137. }
  138. },
  139. computed: {
  140. ...mapGetters(['authArrs']),
  141. pageTableHeight () {
  142. if (this.dataFlag) return 'height:100%'
  143. if (this.authId) return 'height:calc(100vh - 180px);padding:0'
  144. return ''
  145. },
  146. pageTableContentHeight () {
  147. if (this.dataFlag) return 'height:calc(100% - 60px)'
  148. if (this.authId) return 'height:calc(100% - 130px)'
  149. return ''
  150. },
  151. pageAuthBtnQuery () {
  152. return this.tableBtns.filter(item => item.servicetype == 0)[0]
  153. },
  154. pageAuthBtnDetail () {
  155. return this.tableBtns.filter(item => item.servicetype == 1)[0]
  156. },
  157. pageAuthBtnAdd () {
  158. return this.tableBtns.filter(item => item.servicetype == 2)[0]
  159. },
  160. pageAuthBtnEdit () {
  161. return this.tableBtns.filter(item => item.servicetype == 3)[0]
  162. },
  163. pageAuthBtnDel () {
  164. return this.tableBtns.filter(item => item.servicetype == 4)[0]
  165. },
  166. pageAuthBtnOther () {
  167. return this.tableBtns.filter(item => item.servicetype == 5)[0]
  168. },
  169. pageAuthBtnExport () {
  170. return this.tableBtns.filter(item => item.servicetype == 6)[0]
  171. },
  172. pageAuthBtnInstall () {
  173. return this.pageInstall == this.$route.path.replace('/', '')
  174. }
  175. },
  176. watch: {
  177. routerlist: {
  178. handler (row) {
  179. if (row && Object.keys(row).length) {
  180. this.authId ? this.pageInit(this.authId) : this.pageInit()
  181. this.queryTableData(true)
  182. }
  183. }
  184. },
  185. msgContent: {
  186. handler (row) {
  187. if (row && Object.keys(row).length) {
  188. const { passparameters } = row
  189. const filterItem = this.formatDefault(passparameters, row)
  190. if (!Object.keys(filterItem).length) return
  191. this.defaultfilter = filterItem
  192. this.queryTableData(true)
  193. }
  194. },
  195. deep: true,
  196. immediate: true
  197. },
  198. authQuery: {
  199. handler (row) {
  200. if (row && Object.keys(row).length) {
  201. this.defaultfilter = row
  202. this.queryTableData(true)
  203. }
  204. },
  205. deep: true,
  206. }
  207. },
  208. mounted () {
  209. this.authId ? this.pageInit(this.authId) : this.pageInit()
  210. },
  211. methods: {
  212. //页面初始化
  213. pageInit (authId) {
  214. //获取页面查询参数
  215. // const { query } = this.$route
  216. // authId ? this.pageQuery = this.authQuery : this.pageQuery = query
  217. //获取页面配置
  218. const { pagecode, qid, auth_id } = this.routerlist && Object.keys(this.routerlist).length ? this.routerlist: this.$route.meta
  219. //获取页面权限类型组件  pagetype 1模块  2页面  3按钮 4表格 5树形  6弹窗
  220. const pageAuths = this.authArrs
  221. if (!pageAuths.length) return
  222. let pageAuthArrs = null
  223. // console.log(pageAuths)
  224. authId ? pageAuthArrs = pageAuths.filter(item => item['superiorid'] == authId) : pageAuthArrs = pageAuths.filter(item => item['superiorid'] == auth_id)
  225. //获取当前页面权限类型
  226. if (!pageAuthArrs.length) return
  227. //获取tree权限
  228. const pageAuthtrees = pageAuthArrs.filter(item => item.pagetype == 'tree')
  229. if (pageAuthtrees?.length){ this.getPageTreeSetting(pageAuthtrees)}else{
  230. this.treeData = []
  231. }
  232. //获取table权限
  233. const pageAuthtables = pageAuthArrs.filter(item => item.pagetype == 'table')
  234. if (pageAuthtables?.length) this.getPageTableSetting(pageAuths, pageAuthtables)
  235. //获取按钮权限
  236. const pageAuthbtns = pageAuthArrs.filter(item => item.pagetype == 'button')
  237. if (pageAuthbtns?.length) this.getPageBtnSetting(pageAuthbtns)
  238. const pageAuthFforms = pageAuthArrs.filter(item => item.pagetype == 'form')
  239. //获取form表单弹框权限
  240. if (pageAuthFforms?.length) this.getPageBtnFormSetting(pageAuths, pageAuthFforms)
  241. },
  242. //根据页面tree设置数据
  243. getPageTreeSetting (pageAuthtrees) {
  244. const { defaultfilter, dropdownlistid, dropdownlistlabel } = pageAuthtrees[0]
  245. this.treeNodeMap = { nodeKey: dropdownlistid, nodeValue: dropdownlistlabel }
  246. this.treeParameters = defaultfilter
  247. this.treeData = pageAuthtrees
  248. },
  249. //根据页面table设置数据
  250. getPageTableSetting (pageAuths, pageAuthtables) {
  251. const authTableObj = pageAuthtables[0]
  252. //获取当前页面table的配置
  253. const { pagename, pageconfigurationid, serviceid, pagecode, userpermissionsid, defaultfilter, selected, triggerserviceid } = authTableObj
  254. //获取当前页面table的按钮权限
  255. const currPageBtns = pageAuths.filter(item => item['superiorid'] == pageconfigurationid && item.pagetype == 'button')
  256. if (currPageBtns?.length) this.tableBtns.push(...currPageBtns)
  257. this.authBtns = pageAuths.filter(item => item.superiorid == pageconfigurationid && item.pagetype == 'button')
  258. this.pageServiceId = Object.keys(this.msgContent).length ? this.msgContent.serviceid : serviceid;
  259. this.pageTitle = pagename
  260. this.selected = selected
  261. this.triggerserviceid = triggerserviceid
  262. this.defaultfilter = Object.keys(this.pageQuery).length ? this.pageQuery : defaultfilter ? this.formatDefault(defaultfilter, authTableObj) : { 1: 1 }
  263. const tableColumnArrs = pageAuths.filter(item => item['superiorid'] == pageconfigurationid && item['pagetype'] == 'column')
  264. this.getColumnData(tableColumnArrs)
  265. },
  266. //根据页面按钮设置数据
  267. getPageBtnSetting (pageAuthbtns) {
  268. this.tableBtns.push(...pageAuthbtns)
  269. },
  270. //根据页面按钮设置表单form数据
  271. getPageBtnFormSetting (pageAuths, pageAuthForms) {
  272. const { pageconfigurationid } = [...pageAuthForms][0]
  273. const tableColumnArrs = pageAuths.filter(item => item['superiorid'] == pageconfigurationid && item['pagetype'] == 'column')
  274. const formItemCopy = tableColumnArrs.filter((item) => item.isdisplay != 0)
  275. this.formItem = _.orderBy(formItemCopy, ['displaynumber'], ['asc'])
  276. },
  277. //获取表头数据
  278. getColumnData (columnArrs = []) {
  279. const returnData = [...columnArrs]
  280. this.$store.dispatch('auth/changeAuthMsg', returnData)
  281. const tableColsCopy = _.cloneDeep(returnData).filter((item) => item.isdisplay != 0)
  282. const tableColsCopyOrder = _.orderBy(tableColsCopy, ['displaynumber'], ['asc'])
  283. // const formItemCopy = _.cloneDeep(returnData).filter((item) => item.isdisplay == 2 || item.isdisplay == 3);
  284. // this.formItem = _.orderBy(formItemCopy, ['displaynumber'], ['asc']);
  285. const msgCounts = tableColsCopyOrder.filter(item => item.enablecount)
  286. const simpleQueryItem = _.cloneDeep(returnData).filter((item) => item.easysearch && item.isfiltercolumn)
  287. if (msgCounts.length) {
  288. this.summaryFlag = true
  289. }
  290. this.tableCols = listToTree(tableColsCopyOrder, 'groupid', 'pagecode')
  291. const columncode = returnData.find(
  292. (item) => item.isprimarykey == 1
  293. )
  294. if (columncode && Object.keys(columncode).length) {
  295. this.tableKey = columncode['pagecode']
  296. }
  297. if (simpleQueryItem?.length) {
  298. this.simpleQueryFlag = true
  299. this.simpleQueryItem = simpleQueryItem
  300. }
  301. },
  302. //获取tree点击
  303. treeNodeClick (data) {
  304. const nrow = _.cloneDeep(data)
  305. this.selectedDataCheck = nrow
  306. if (this.selected) {
  307. this.treeCheckQuery(nrow)
  308. } else {
  309. const values = Object.values(data)
  310. const filterItem = this.formatDefault(this.treeParameters, data)
  311. if (!Object.keys(filterItem).length) return
  312. this.defaultfilter = values.includes(-1) || values.includes('全部') ? { 1: 1 } : filterItem
  313. this.queryTableData(true)
  314. }
  315. },
  316. //存在勾选-点击树-查询
  317. async treeCheckQuery (data) {
  318. const values = Object.values(data)
  319. const filterItem = this.formatDefault(this.treeParameters, data)
  320. if (!Object.keys(filterItem).length) return
  321. const itemFilter = values.includes(-1) || values.includes('全部') ? { 1: 1 } : filterItem
  322. const datacontent = { filter: itemFilter }
  323. this.loading = true
  324. this.selectedDataAlls = []
  325. try {
  326. const { code, returnData } = await Query({
  327. page: 1,
  328. serviceid: this.triggerserviceid,
  329. datacontent,
  330. event: '0',
  331. size: 9999
  332. });
  333. if (code == 0) {
  334. const datas = []
  335. this.tableData.filter(item => {
  336. [...returnData].forEach(pt => {
  337. if (item['serviceid'] == pt['serviceid']) {
  338. datas.push(item)
  339. }
  340. })
  341. })
  342. this.selectedDatas = [...datas]
  343. this.selectedDatasCath = [...returnData]
  344. this.selectedDataAlls.push([...datas])
  345. } else {
  346. this.$message.error("获取表格数据失败")
  347. }
  348. } catch (error) {
  349. this.$message.error("获取表格数据失败")
  350. }
  351. this.loading = false
  352. },
  353. //格式化传递参数数据
  354. formatDefault (item, data = {}) {
  355. if (typeof item != 'string') return {}
  356. const filterItem = {}
  357. const parameters = item.replace('{', '').replace('}', '')
  358. const parametersSplit = parameters?.split(',')
  359. parametersSplit.map(item => {
  360. const [key, val] = item?.split(':')
  361. filterItem[key] = data[val]
  362. })
  363. return filterItem
  364. },
  365. //根据按钮权限查询表单权限
  366. findBtntoForm (pageroute) {
  367. return this.tableBtnForms.filter(item => item.pagecode == pageroute)
  368. },
  369. //表单-查看
  370. handleDetail (row) {
  371. const { openmode, pageroute } = this.pageAuthBtnDetail
  372. if (!openmode) return
  373. if (openmode != 2) this.autoBtnClick(openmode, pageroute)
  374. this.flag = true
  375. this.formAuth = false
  376. this.tableType = "detail"
  377. this.tableTitle = "查看"
  378. this.tableForm = _.cloneDeep(row)
  379. },
  380. //表单-新增
  381. async handleAdd () {
  382. const { openmode, pageroute, pagecode } = this.pageAuthBtnAdd
  383. if (!openmode) return
  384. // if (!this.findBtntoForm(pageroute).length) return
  385. if (openmode != 2) this.autoBtnClick(openmode, pageroute)
  386. // const { pageconfigurationid } = this.findBtntoForm(pageroute)[0]
  387. // const pageAuths = this.authArrs
  388. // const tableColumnArrs = pageAuths.filter(item => item['superiorid'] == pageconfigurationid && item['pagetype'] == 'column')
  389. // this.dialogName = pageroute
  390. if (pagecode == 'startBtnAll') {
  391. if (!Object.keys(this.selectedDataCheck).length) {
  392. this.$message.error('请选中容器后再操作')
  393. return
  394. }
  395. const { code, message } = await startAll(this.selectedDataCheck)
  396. if (code == 0) {
  397. this.$message.success(message || '操作成功')
  398. this.queryTableData(true)
  399. } else {
  400. this.$message.error(message || '操作失败')
  401. }
  402. } else {
  403. if (this.$refs['ruleForm']) {
  404. this.$nextTick(() => {
  405. this.$refs['ruleForm'].restForm()
  406. })
  407. }
  408. this.flag = true;
  409. this.tableType = "add"
  410. this.tableTitle = "新增"
  411. this.tableForm = {}
  412. for (let k in this.defaultfilter) {
  413. if (k != 1) {
  414. this.tableForm[k] = this.defaultfilter[k]
  415. }
  416. }
  417. for (let k in this.formItem) {
  418. if (this.formItem[k].defaultvalue && this.formItem[k].defaultvalue != "") {
  419. this.$set(this.tableForm, this.formItem[k].pagecode, this.formItem[k].defaultvalue)
  420. }
  421. }
  422. }
  423. // this.formItem = tableColumnArrs.filter(item => item.isdisplay == 1)
  424. },
  425. formatData (returnData) {
  426. return typeof returnData == 'string' ? this.retParse(returnData) : returnData
  427. },
  428. retParse (returnData) {
  429. try {
  430. return JSON.parse(returnData) ? JSON.parse(returnData) : returnData
  431. } catch (error) {
  432. return returnData
  433. }
  434. },
  435. //回显下拉数据
  436. resPassters (obj) {
  437. const narr = []
  438. const nitem = _.cloneDeep(obj)
  439. const { passparameters } = nitem
  440. if (!passparameters) return ''
  441. const ndata = this.formatData(passparameters)
  442. if (!Array.isArray(ndata)) return ''
  443. ndata.map(({ pageconfigurationid }) => { narr.push(pageconfigurationid) })
  444. return narr
  445. },
  446. //表格-编辑
  447. handleEdit (row) {
  448. const { openmode, pageroute } = this.pageAuthBtnEdit
  449. if (!openmode) return
  450. if (openmode != 2) this.autoBtnClick(openmode, pageroute)
  451. this.flag = true
  452. this.tableType = "edit"
  453. this.tableTitle = "编辑"
  454. const nrow = _.cloneDeep(row)
  455. if (nrow.passparameters) {
  456. nrow.passparameters = this.resPassters(row)
  457. }
  458. if (nrow.dropdownlist) {
  459. nrow.dropdownlist = Number(nrow.dropdownlist)
  460. }
  461. this.tableForm = nrow
  462. },
  463. //表格-其他类型按钮操作
  464. handleOther (row, auth) {
  465. const { openmode, pageroute, passparameters } = this.pageAuthBtnOther
  466. if (!openmode) return
  467. if (openmode != 2) this.autoBtnClick(openmode, pageroute, passparameters, row)
  468. const { pagecode } = auth
  469. if (pagecode == 'stopBtn' || pagecode == 'startBtn') {
  470. this.stateChange(row)
  471. }
  472. },
  473. //启动 & 停止
  474. async stateChange (row) {
  475. const { runstate, serviceid, containercode } = row
  476. const filter = { serviceid, containercode }
  477. if (runstate == 1) {
  478. const { code, returnData } = await stop(filter)
  479. if (code == 0) {
  480. this.$message.success(returnData || '操作成功')
  481. this.queryTableData(true)
  482. } else {
  483. this.$message.error(returnData || '操作失败')
  484. }
  485. } else {
  486. const { code, returnData } = await start(filter)
  487. if (code == 0) {
  488. this.$message.success(returnData || '操作成功')
  489. this.queryTableData(true)
  490. } else {
  491. this.$message.error(returnData || '操作失败')
  492. }
  493. }
  494. },
  495. //表格-删除
  496. handleRemove (row) {
  497. const { openmode, pageroute } = this.pageAuthBtnDel
  498. if (!openmode) return
  499. if (openmode != 2) this.autoBtnClick(openmode, pageroute)
  500. let name = ''
  501. const nrow = _.cloneDeep(row)
  502. for (const key in nrow) {
  503. if (key.includes('name')) {
  504. name = nrow[key] || ''
  505. }
  506. }
  507. this.$confirm(`确认要删除 ${name} 这条信息吗?`, '提示', {
  508. confirmButtonText: '确定',
  509. cancelButtonText: '取消',
  510. type: 'warning'
  511. }).then(() => {
  512. this.generalDataReception(3, row, this.tableKey)
  513. }).catch(() => {
  514. this.$message({
  515. type: 'info',
  516. message: '已取消删除'
  517. });
  518. });
  519. },
  520. //表格-勾选
  521. handleSelectionChange (val) {
  522. this.selectedDataAlls.push([...val])
  523. const ndatas = _.cloneDeep(this.selectedDataAlls)
  524. if (ndatas.length == 1) {
  525. this.sendCheckData('add', ndatas[0])
  526. } else {
  527. const [nitems1, nitems2] = [ndatas.at(-1), ndatas.at(-2)]
  528. if (nitems1.length > nitems2.length) {
  529. const res = this.findRepetData(nitems1, nitems2)
  530. this.sendCheckData('add', res)
  531. } else {
  532. const res = this.findRepetData(nitems1, nitems2)
  533. this.sendCheckData('del', res)
  534. }
  535. }
  536. },
  537. findRepetData (nitems1, nitems2) {
  538. const key = 'serviceid'
  539. const res = [...nitems1, ...nitems2].filter(
  540. (item) =>
  541. !(
  542. nitems1.some((p) => item[key] == p[key]) &&
  543. nitems2.some((c) => item[key] == c[key])
  544. )
  545. )
  546. return res
  547. },
  548. //发送新增编辑删除数据
  549. sendCheckData (types, data, key = 'serviceid') {
  550. const event = types == 'add' ? 1 : types == 'edit' ? 2 : 3
  551. const querys = []
  552. const items = _.cloneDeep(data)
  553. const { serviceid, servicename } = items[0]
  554. const { containerid, containercode, containername } = this.selectedDataCheck
  555. const pitem = {
  556. serviceid,
  557. servicename,
  558. containerid,
  559. containercode,
  560. containername
  561. }
  562. const params = {
  563. serviceid: this.triggerserviceid,
  564. datacontent: formatChange(pitem, event, key),
  565. event,
  566. }
  567. if (event == 3) {
  568. params.datacontent[0].filter.containerid = containerid
  569. delete params.datacontent[0].value.containerid
  570. }
  571. event == 1 ? querys.push(newData(params)) : querys.push(moveData(params))
  572. this.getAnscyData(querys)
  573. },
  574. //获取异步数据
  575. async getAnscyData (allResult) {
  576. if (!allResult.length) return
  577. this.loading = true
  578. const results = await Promise.allSettled(allResult)
  579. results.map((item) => {
  580. const { status, value } = item
  581. if (status == 'fulfilled') {
  582. const { code } = value
  583. if (code == 0) {
  584. this.treeCheckQuery(this.selectedDataCheck)
  585. this.$message.success('操作成功')
  586. } else {
  587. this.$message.error('操作失败')
  588. }
  589. } else {
  590. this.$message.error('网络错误')
  591. }
  592. })
  593. // this.loading = false
  594. },
  595. // 新增/编辑-取消
  596. submitClickClose (formName) {
  597. this.formAuth = true
  598. this.flag = false
  599. this.$refs[formName].restForm()
  600. },
  601. // 新增/编辑-确认
  602. submitClickHandler () {
  603. const flag = this.$refs["ruleForm"].submitClickHandler()
  604. if (flag) this.tableType == "add" ? this.generalDataReception(1, this.tableForm) : this.generalDataReception(2, this.tableForm, this.tableKey)
  605. },
  606. //表格-增/删/改
  607. async generalDataReception (event, data, key) {
  608. this.dialogLoading = true
  609. try {
  610. const params = {
  611. serviceid: this.pageServiceId,
  612. datacontent: formatChange(data, event, key),
  613. event: `${event}`,
  614. };
  615. const { code } =
  616. event == 1
  617. ? await newData(params)
  618. : event == 2
  619. ? await modifyData(params)
  620. : await moveData(params);
  621. if (code == 0) {
  622. this.$message.success("操作成功")
  623. this.flag = false
  624. this.rmFlag = false
  625. this.dialogLoading = false
  626. this.tableObj = {}
  627. this.tableForm = {}
  628. this.resetTable()
  629. this.load();
  630. this.depMath = Math.random()
  631. // this.$router.go(0);
  632. } else {
  633. this.$message.error("操作失败");
  634. this.flag = false
  635. this.rmFlag = false
  636. this.dialogLoading = false
  637. this.tableObj = {};
  638. this.tableForm = {};
  639. }
  640. } catch (error) {
  641. this.flag = false
  642. this.rmFlag = false
  643. this.dialogLoading = false
  644. this.tableObj = {}
  645. this.tableForm = {}
  646. }
  647. },
  648. autoBtnClick (id, url, passparameters, row = {}) {
  649. switch (Number(id)) {
  650. case 1:
  651. if (passparameters && Object.keys(row).length) {
  652. const filterItem = this.formatDefault(passparameters, row)
  653. this.$router.push({
  654. path: url,
  655. query: filterItem
  656. })
  657. }
  658. break;
  659. case 2:
  660. this.$router.push(url)
  661. break;
  662. default:
  663. break;
  664. }
  665. },
  666. //高级查询-弹框打开
  667. async handleQuery () {
  668. const { openmode, pageroute, pagecode } = this.pageAuthBtnQuery
  669. if (!openmode) return
  670. if (pagecode == 'stopBtnAll') {
  671. if (!Object.keys(this.selectedDataCheck).length) {
  672. this.$message.error('请选中容器后再操作')
  673. return
  674. }
  675. const { code, message } = await stopAll(this.selectedDataCheck)
  676. if (code == 0) {
  677. this.$message.success(message || '操作成功')
  678. this.queryTableData(true)
  679. } else {
  680. this.$message.error(message || '操作失败')
  681. }
  682. } else {
  683. if (openmode != 3) this.advancedDrawer = true // this.autoBtnClick(openmode, pageroute)
  684. }
  685. },
  686. //简易查询-确定
  687. queryValue (dataRules) {
  688. const arr = [...dataRules]
  689. const arrmap = {}
  690. if (arr?.length) {
  691. arr.forEach(item => {
  692. const { column, value } = item
  693. item.value = typeof value == 'string' ? value.replace(/\s*/g, "") : value
  694. arrmap[column] = value
  695. })
  696. }
  697. this.defaultfilter = Object.keys(arrmap).length ? arrmap : arr.length ? arr : { 1: 1 }
  698. this.simpleQueryValue = arr
  699. this.queryTableData(true)
  700. },
  701. //高级查询-确定
  702. advancedTable (refName) {
  703. this.$refs[refName].advancedQueryHandler()
  704. },
  705. //高级查询-取消
  706. advancedClose () {
  707. this.advancedDrawer = false
  708. // this.defaultfilter = { 1: 1 }
  709. // this.queryTableData(true)
  710. },
  711. //初始化
  712. onInstall () {
  713. if (!Object.keys(this.selectedDataCheck).length) {
  714. this.$message.error('请选中权限后再操作')
  715. return
  716. }
  717. const { pagetype } = this.selectedDataCheck
  718. if (pagetype != 'table') {
  719. this.$message.error('请选择表格后再操作')
  720. return
  721. }
  722. this.installFlag = true
  723. },
  724. //初始化-关闭
  725. installClose () {
  726. this.installFlag = false
  727. },
  728. //初始化-确定
  729. installTable () {
  730. this.installSubmit()
  731. this.installFlag = false
  732. },
  733. async installSubmit () {
  734. const { pageconfigurationid } = this.selectedDataCheck
  735. const { code, returnData } = await Query({
  736. serviceid: 134,
  737. datacontent: {
  738. tableName: this.$refs['installForm'].tableinfo,
  739. datasourceid: this.$refs['installForm'].datasourceid,
  740. pageconfigurationid
  741. },
  742. deletedatacontent: {
  743. datacontent: [
  744. {
  745. filter: {
  746. superiorid: pageconfigurationid
  747. },
  748. value: {}
  749. }
  750. ],
  751. event: '3'
  752. },
  753. event: '0'
  754. })
  755. if (code == 0 && returnData?.length) {
  756. this.$message.success('数据初始化成功')
  757. this.$refs['pageTree'].pageInit()
  758. this.queryTableData(true)
  759. this.$refs['installForm'].tableinfo = ''
  760. this.$refs['installForm'].datasourceid = ''
  761. }
  762. },
  763. //高级查询-确定-数据
  764. getAdvancedQueryData (dataRules) {
  765. const arr = [...dataRules]
  766. if (arr && arr.length) {
  767. arr.forEach(item => {
  768. item.value = typeof item.value == 'string' ? item.value.replace(/\s*/g, "") : item.value
  769. })
  770. }
  771. this.defaultfilter = arr
  772. this.advancedQueryValue = arr
  773. this.queryTableData(true)
  774. },
  775. //高级查询-收藏
  776. queryCollect (refName) {
  777. this.$refs[refName].advancedQueryCollect()
  778. },
  779. //高级查询-重置
  780. restCollect (refName) {
  781. this.defaultfilter = { 1: 1 }
  782. this.queryTableData(true)
  783. this.$refs[refName].advancedRestCollect()
  784. },
  785. // 给表头单元格加上 ascending 或 descending 使用 element 自带的排序箭头变色
  786. headerCellClass () {
  787. return function ({ row, column, rowIndex, columnIndex }) {
  788. const classes = []
  789. const rule = this.tableDataSortRules[column.property]
  790. if (rule) {
  791. classes.push(rule)
  792. }
  793. return classes.join(' ')
  794. }
  795. },
  796. //添加-表格-行样式
  797. rowClass () {
  798. return function ({ row, rowIndex }) {
  799. const classes = []
  800. if (row.deleted === 'DEL') {
  801. classes.push('bgl-deleted')
  802. }
  803. return classes.join(' ')
  804. }
  805. },
  806. //添加-表格-单元格样式
  807. cellClass () {
  808. return function ({ row, column, rowIndex, columnIndex }) {
  809. const classes = []
  810. const { property } = column
  811. const ndata = _.cloneDeep(this.tableCols).filter(item => item.pagecode == property)
  812. if (ndata?.length) {
  813. const { pageroute } = ndata[0]
  814. if (pageroute) classes.push('cell-click')
  815. }
  816. return classes.join(' ')
  817. }
  818. },
  819. formatPass (pass = []) {
  820. if (typeof pass != 'string') return {}
  821. const ndata = JSON.parse(pass)
  822. if (!ndata) return {}
  823. const nitem = {}
  824. ndata.map(item => {
  825. const ns = Object.values(item)
  826. nitem[ns[0]] = ns[1]
  827. })
  828. return nitem
  829. },
  830. //添加-表格-单元格-点击事件
  831. cellClickHandler (row, column, cell, event) {
  832. const { property } = column
  833. const ndata = _.cloneDeep(this.tableCols).filter(item => item.pagecode == property)
  834. const params = {}
  835. if (ndata?.length) {
  836. const { defaultfilter, pageroute, passparameters } = ndata[0]
  837. if (!pageroute) return
  838. if (defaultfilter || passparameters) {
  839. if (passparameters) {
  840. // const nitem = this.formatPass(passparameters)
  841. const passparametersArray = JSON.parse(passparameters)
  842. passparametersArray.map(item => {
  843. if (row[item.pagecode]) {
  844. const alias = item.alias
  845. const pagecode = item.pagecode
  846. if (alias) {
  847. params[alias] = row[item['pagecode']]
  848. }
  849. else {
  850. params[pagecode] = row[item['pagecode']]
  851. }
  852. }
  853. })
  854. this.$router.push({
  855. path: pageroute,
  856. query: params
  857. })
  858. return
  859. }
  860. if (defaultfilter) {
  861. const filterItem = this.formatDefault(defaultfilter, row)
  862. this.$router.push({
  863. path: pageroute,
  864. query: filterItem
  865. })
  866. return
  867. }
  868. }
  869. else {
  870. this.$router.push(pageroute)
  871. }
  872. }
  873. },
  874. //导出
  875. handleExport () {
  876. if (!this.tableData.length) {
  877. this.$message.info('无数据')
  878. return
  879. }
  880. const table = this.$refs['table'].$el.cloneNode(true)
  881. const fileName = this.pageTitle + '.xlsx'
  882. exportToExcel(table, this.pageTitle, fileName)
  883. },
  884. tableFormatter () {
  885. return function (row, column, cellValue) {
  886. switch (column.property) {
  887. case 'departureTime':
  888. return (cellValue ?? '').replace('T', ' ')
  889. case 'deleted':
  890. return cellValue === 'DEL' ? cellValue : ''
  891. case 'activated':
  892. return Number(cellValue) === 1 ? '激活' : '未激活'
  893. default:
  894. return cellValue ?? ''
  895. }
  896. }
  897. },
  898. tableMountedHandler (refName, ref) {
  899. this.$refs[refName] = ref
  900. },
  901. resetTable () {
  902. this.dataContent = {}
  903. this.page = 0;
  904. this.noMore = false;
  905. this.tableData = [];
  906. },
  907. load () {
  908. if (this.noMore || this.loading) {
  909. return
  910. }
  911. this.queryTableData()
  912. },
  913. async queryTableData (jumpSing = false) {
  914. if (jumpSing) {
  915. const initialize = _.once(this.resetTable)
  916. initialize()
  917. }
  918. this.loading = true;
  919. const datacontent = { filter: this.defaultfilter }
  920. const parmas = {
  921. page: ++this.page,
  922. serviceid: this.pageServiceId,
  923. datacontent,
  924. event: '0'
  925. }
  926. if (this.selected || this.pageSizeDatas.includes(this.$route.path.replace('/', ''))) {
  927. parmas.size = 9999
  928. }
  929. try {
  930. const { code, returnData } = await Query(parmas);
  931. if (code == 0) {
  932. if (returnData.length === 0) {
  933. this.page--
  934. this.noMore = true
  935. }
  936. this.tableData.push(...returnData)
  937. } else {
  938. this.page--
  939. this.noMore = true
  940. this.$message.error("获取表格数据失败")
  941. }
  942. } catch (error) {
  943. this.page--
  944. this.noMore = true
  945. }
  946. if (this.selected || this.pageSizeDatas.includes(this.$route.path.replace('/', ''))) {
  947. this.noMore = true
  948. }
  949. this.loading = false
  950. }
  951. }
  952. }
  953. </script>
  954. <style lang="scss" scoped>
  955. .TablePage {
  956. height: calc(100vh - 90px);
  957. padding: 20px;
  958. &_content {
  959. margin-top: 20px;
  960. height: calc(100vh - 190px);
  961. &_left {
  962. width: 360px;
  963. margin-right: 20px;
  964. }
  965. &_right {
  966. }
  967. .tableAuto {
  968. width: 100%;
  969. }
  970. .tableSacle {
  971. width: calc(100% - 380px);
  972. }
  973. }
  974. }
  975. </style>