JeecgListMixin.js 14 KB

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