JeecgListMixin.js 13 KB

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