JeecgListMixin.js 12 KB

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