JeecgListMixin.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /**
  2. * 新增修改完成调用 modalFormOk方法 编辑弹框组件ref定义为modalForm
  3. * 高级查询按钮调用 superQuery方法 高级查询组件ref定义为superQueryModal
  4. * data中url定义 list为查询列表 delete为删除单条记录 deleteBatch为批量删除
  5. */
  6. import {filterObj} from '@/utils/util';
  7. import moment from 'moment'
  8. import {deleteAction, getAction, downFile} from '@/api/manage'
  9. import Vue from 'vue'
  10. import {ACCESS_TOKEN} from "@/store/mutation-types"
  11. import { transformTozTreeFormat } from '@/utils/util.js'
  12. import {mapGetters} from 'vuex';
  13. export const JeecgListMixin = {
  14. data() {
  15. return {
  16. spinning:true,
  17. //token header
  18. tokenHeader: {'X-Access-Token': Vue.ls.get(ACCESS_TOKEN)},
  19. /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
  20. queryParam: {},
  21. /* 数据源 */
  22. dataSource: [],
  23. innerData:[],
  24. /* 分页参数 */
  25. ipagination: {
  26. current: 1,
  27. pageSize: 10,
  28. pageSizeOptions: ['10', '20', '30'],
  29. showTotal: (total, range) => {
  30. return range[0] + "-" + range[1] + " 共" + total + "条"
  31. },
  32. showQuickJumper: true,
  33. // showSizeChanger: true,
  34. total: 0,
  35. onChange: (current) => {
  36. // 切换分页时的回调,
  37. // 当在页面定义change事件时,切记要把此处的事件清除,因为这两个事件重叠了,可能到时候会导致一些莫名的bug
  38. this.ipagination.current = current
  39. this.loadData();
  40. },
  41. },
  42. /* 排序参数 */
  43. isorter: {
  44. column: 'createTime',
  45. order: 'desc',
  46. },
  47. /* 筛选参数 */
  48. filters: {},
  49. /* table加载状态 */
  50. loading: false,
  51. /* table选中keys*/
  52. selectedRowKeys: [],
  53. /* table选中records*/
  54. selectionRows: [],
  55. /* 查询折叠 */
  56. toggleSearchStatus: false,
  57. /* 高级查询条件生效状态 */
  58. superQueryFlag: false,
  59. /* 高级查询条件 */
  60. superQueryParams: ""
  61. }
  62. },
  63. mounted() {
  64. if(this.startList){
  65. }else{
  66. this.loadData();
  67. }
  68. //初始化字典配置 在自己页面定义
  69. this.initDictConfig();
  70. },
  71. methods: {
  72. ...mapGetters(['nickname', 'avatar', 'userInfo']),
  73. // 二级树
  74. expand(expanded,record){
  75. if(this.url.listTwo){
  76. var param = {}
  77. param.field = this.getQueryField();
  78. param.pageNo = this.ipagination.current;
  79. param.pageSize = this.ipagination.pageSize;
  80. param.parentId = record.id
  81. if(expanded){
  82. getAction(this.url.listTwo, filterObj(param)).then((res) => {
  83. if (res.success) {
  84. record.innerData=res.result.records.map((item,index)=>{
  85. return {
  86. ...item,
  87. key:index
  88. }
  89. })
  90. // console.log(record.innerData)
  91. record.innerData = transformTozTreeFormat( record.innerData)
  92. }
  93. if (res.code === 510) {
  94. this.$message.warning(res.message)
  95. }
  96. this.loading = false;
  97. })
  98. }else{
  99. record.innerData = []
  100. }
  101. }
  102. },
  103. async loadData(arg) {
  104. this.cancel()
  105. this.spinning= true
  106. this.dataSource = []
  107. if (!this.url.list) {
  108. this.$message.error("请设置url.list属性!")
  109. return
  110. }
  111. //加载数据 若传入参数1则加载第一页的内容
  112. if (arg === 1) {
  113. this.ipagination.current = 1;
  114. }
  115. var params = this.getQueryParams();//查询条件
  116. if(params.createTime&&params.createTime.length>0){
  117. // params.createTime = moment(params.createTime).format('YYYY-MM-DD')
  118. params.startDate = moment(params.createTime[0]).format('YYYY-MM-DD')
  119. params.endDate = moment(params.createTime[1]).format('YYYY-MM-DD')
  120. params.createTime = null
  121. }
  122. if(params.stateDate){
  123. params.stateDate = moment(params.stateDate).format('YYYY-MM-DD')
  124. }
  125. if(params.videoStatus == 0){
  126. params.syncKuaishou = null
  127. params.syncBytedance = null
  128. }else if(params.videoStatus == 1){
  129. params.syncKuaishou = 1
  130. params.syncBytedance = 1
  131. }else if(params.videoStatus == '2'){
  132. params.syncKuaishou = 1
  133. params.syncBytedance = null
  134. }else if(params.videoStatus == 3){
  135. params.syncKuaishou = null
  136. params.syncBytedance = 1
  137. }else if(params.videoStatus == 4){
  138. params.syncKuaishou = 2
  139. params.syncBytedance = null
  140. }else if(params.videoStatus == 5){
  141. params.syncKuaishou = null
  142. params.syncBytedance = 2
  143. }else if(params.videoStatus == 6){
  144. params.syncKuaishou = 2
  145. params.syncBytedance = 2
  146. }else{
  147. params.syncKuaishou = null
  148. params.syncBytedance = null
  149. }
  150. // if(params.endDate){
  151. // params.endDate = moment(params.endDate).format('YYYY-MM-DD')
  152. // }
  153. if(params.userId){
  154. }else{
  155. params.userId = this.userInfo().id
  156. }
  157. if(params.monthTime&&params.monthTime.length>0){
  158. // params.createTime = moment(params.createTime).format('YYYY-MM-DD')
  159. params.startMonth = moment(params.monthTime[0]).format('YYYY-MM')
  160. params.endMonth = moment(params.monthTime[1]).format('YYYY-MM')
  161. params.monthTime = null
  162. }
  163. this.loading = true;
  164. await getAction(this.url.list, params).then((res) => {
  165. if (res.success) {
  166. this.loading = false;
  167. if(res.result){
  168. if(res.result.records){
  169. this.dataSource = res.result.records.map(item=>{
  170. return {
  171. ...item,
  172. innerData:[],
  173. showVideo:false
  174. }
  175. })
  176. this.ipagination.total = res.result.total;
  177. }else if(res.result.list){
  178. this.dataSource = res.result.list.map(item=>{
  179. return {
  180. ...item,
  181. innerData:[],
  182. showVideo:false
  183. }
  184. })
  185. this.ipagination.total = res.result.total;
  186. }else{
  187. this.dataSource = res.result.map(item=>{
  188. return {
  189. ...item,
  190. innerData:[],
  191. showVideo:false
  192. }
  193. })
  194. // this.ipagination = null;
  195. this.ipagination.pageSize=res.result.length
  196. }
  197. }else if(res.data){
  198. if(res.data.list){
  199. this.dataSource = res.data.list.map(item=>{
  200. return {
  201. ...item,
  202. innerData:[],
  203. showVideo:false
  204. }
  205. })
  206. this.ipagination.total = res.data.total;
  207. }
  208. }
  209. this.spinning= false
  210. }
  211. if (res.code === 510) {
  212. this.$message.warning(res.message)
  213. }
  214. this.loading = false;
  215. this.spinning= false
  216. })
  217. },
  218. initDictConfig() {
  219. // console.log("--这是一个假的方法!")
  220. },
  221. handleSuperQuery(arg) {
  222. //高级查询方法
  223. if (!arg) {
  224. this.superQueryParams = ''
  225. this.superQueryFlag = false
  226. } else {
  227. this.superQueryFlag = true
  228. this.superQueryParams = JSON.stringify(arg)
  229. }
  230. this.loadData()
  231. },
  232. editDate(value) {
  233. let date = new Date(value)
  234. let y = date.getFullYear()
  235. let MM = date.getMonth() + 1
  236. MM = MM < 10 ? '0' + MM : MM
  237. let d = date.getDate()
  238. d = d < 10 ? '0' + d : d
  239. return y + '-' + MM + '-' + d
  240. },
  241. getQueryParams() {
  242. //获取查询条件
  243. let sqp = {}
  244. if (this.superQueryParams) {
  245. sqp['superQueryParams'] = encodeURI(this.superQueryParams)
  246. }
  247. // console.log(this.queryParam)
  248. var param = {...this.queryParam,...this.isorter, ...this.filters}
  249. param.pageNo = this.ipagination.current;
  250. param.pageSize = this.ipagination.pageSize;
  251. return param
  252. },
  253. getQueryField() {
  254. //TODO 字段权限控制
  255. var str = "id,";
  256. this.columns.forEach(function (value) {
  257. str += "," + value.dataIndex;
  258. });
  259. return str;
  260. },
  261. onSelectChange(selectedRowKeys, selectionRows) {
  262. this.selectedRowKeys = selectedRowKeys;
  263. this.selectionRows = selectionRows;
  264. },
  265. onClearSelected() {
  266. this.selectedRowKeys = [];
  267. this.selectionRows = [];
  268. },
  269. searchQuery() {
  270. this.loadData(1);
  271. },
  272. superQuery() {
  273. this.$refs.superQueryModal.show();
  274. },
  275. searchReset() {
  276. this.queryParam = {}
  277. this.loadData(1);
  278. },
  279. batchDel: function () {
  280. if (!this.url.deleteBatch) {
  281. this.$message.error("请设置url.deleteBatch属性!")
  282. return
  283. }
  284. if (this.selectedRowKeys.length <= 0) {
  285. this.$message.warning('请选择一条记录!');
  286. return;
  287. } else {
  288. var ids = "";
  289. for (var a = 0; a < this.selectedRowKeys.length; a++) {
  290. ids += this.selectedRowKeys[a] + ",";
  291. }
  292. var that = this;
  293. this.$confirm({
  294. title: "确认删除",
  295. content: "是否删除选中数据?",
  296. onOk: function () {
  297. deleteAction(that.url.deleteBatch, {ids: ids}).then((res) => {
  298. if (res.success) {
  299. that.$message.success(res.message);
  300. that.loadData();
  301. that.onClearSelected();
  302. } else {
  303. that.$message.warning(res.message);
  304. }
  305. });
  306. }
  307. });
  308. }
  309. },
  310. handleDelete: function (id) {
  311. if (!this.url.delete) {
  312. this.$message.error("请设置url.delete属性!")
  313. return
  314. }
  315. var that = this;
  316. deleteAction(that.url.delete, {id: id}).then((res) => {
  317. if (res.success) {
  318. that.$message.success(res.message);
  319. that.loadData();
  320. } else {
  321. that.$message.warning(res.message);
  322. }
  323. });
  324. },
  325. handleEdit: function (record,sign) {
  326. // console.log(record,sign)
  327. this.$refs.modalForm.edit(record,sign);
  328. this.$refs.modalForm.title = "编辑";
  329. this.$refs.modalForm.disableSubmit = false;
  330. if(sign == 'preview'){
  331. this.$refs.modalForm.title = "预览";
  332. }
  333. },
  334. handleImagePreview: function (record) {
  335. this.$refs.modalForm.imagePreview(record);
  336. this.$refs.modalForm.title = "预览";
  337. this.$refs.modalForm.disableSubmit = false;
  338. },
  339. handleAdd: function (sign) {
  340. this.$refs.modalForm.add(sign);
  341. this.$refs.modalForm.title = "新增";
  342. this.$refs.modalForm.disableSubmit = false;
  343. },
  344. handleOpen: function () {
  345. this.$refs.userForm.open();
  346. this.$refs.userForm.title = "选择";
  347. this.$refs.userForm.disableSubmit = false;
  348. },
  349. handleTableChange(pagination, filters, sorter) {
  350. //分页、排序、筛选变化时触发
  351. //TODO 筛选
  352. if (Object.keys(sorter).length > 0) {
  353. this.isorter.column = sorter.field;
  354. this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
  355. }
  356. this.ipagination = pagination;
  357. this.loadData();
  358. },
  359. handleToggleSearch() {
  360. this.toggleSearchStatus = !this.toggleSearchStatus;
  361. },
  362. modalFormOk() {
  363. // 新增/修改 成功时,重载列表
  364. this.loadData(this.ipagination.current);
  365. },
  366. handleDetail: function (record) {
  367. this.$nextTick(()=>{
  368. this.$refs.modalForm.edit(record);
  369. this.$refs.modalForm.title = "详情";
  370. this.$refs.modalForm.disableSubmit = true;
  371. })
  372. },
  373. /* 导出 */
  374. handleExportXls2() {
  375. let paramsStr = encodeURI(JSON.stringify(this.getQueryParams()));
  376. let url = `${window._CONFIG['domianURL']}/${this.url.exportXlsUrl}?paramsStr=${paramsStr}`;
  377. window.location.href = url;
  378. },
  379. handleExportXls(fileName) {
  380. if (!fileName || typeof fileName != "string") {
  381. fileName = "导出文件"
  382. }
  383. let param = {...this.queryParam};
  384. if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
  385. param['selections'] = this.selectedRowKeys.join(",")
  386. }
  387. // console.log("导出参数", param)
  388. downFile(this.url.exportXlsUrl, param).then((data) => {
  389. if (!data) {
  390. this.$message.warning("文件下载失败")
  391. return
  392. }
  393. if (typeof window.navigator.msSaveBlob !== 'undefined') {
  394. window.navigator.msSaveBlob(new Blob([data]), fileName + '.xls')
  395. } else {
  396. let url = window.URL.createObjectURL(new Blob([data]))
  397. let link = document.createElement('a')
  398. link.style.display = 'none'
  399. link.href = url
  400. link.setAttribute('download', fileName + '.xls')
  401. document.body.appendChild(link)
  402. link.click()
  403. document.body.removeChild(link); //下载完成移除元素
  404. window.URL.revokeObjectURL(url); //释放掉blob对象
  405. }
  406. })
  407. },
  408. /* 导入 */
  409. handleImportExcel(info) {
  410. if (info.file.status !== 'uploading') {
  411. // console.log(info.file, info.fileList);
  412. }
  413. if (info.file.status === 'done') {
  414. if (info.file.response.success) {
  415. this.$message.success(`${info.file.name} 文件上传成功`);
  416. this.loadData();
  417. } else {
  418. this.$message.error(`${info.file.name} ${info.file.response.message}.`);
  419. }
  420. } else if (info.file.status === 'error') {
  421. this.$message.error(`文件上传失败: ${info.file.msg} `);
  422. }
  423. },
  424. /* 图片预览 */
  425. getImgView(text) {
  426. if (text && text.indexOf(",") > 0) {
  427. text = text.substring(0, text.indexOf(","))
  428. }
  429. return window._CONFIG['imgDomainURL'] + "/" + text
  430. },
  431. /* 文件下载 */
  432. uploadFile(text) {
  433. if (!text) {
  434. this.$message.warning("未知的文件")
  435. return;
  436. }
  437. if (text.indexOf(",") > 0) {
  438. text = text.substring(0, text.indexOf(","))
  439. }
  440. window.open(window._CONFIG['domianURL'] + "/sys/common/download/" + text);
  441. },
  442. }
  443. }