JeecgListMixin.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. if(res.result.records){
  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. }else{
  132. this.dataSource = res.result.map(item=>{
  133. return {
  134. ...item,
  135. innerData:[],
  136. showVideo:false
  137. }
  138. })
  139. // this.ipagination = null;
  140. this.ipagination.pageSize=res.result.length
  141. }
  142. }
  143. if (res.code === 510) {
  144. this.$message.warning(res.message)
  145. }
  146. this.loading = false;
  147. })
  148. },
  149. initDictConfig() {
  150. // console.log("--这是一个假的方法!")
  151. },
  152. handleSuperQuery(arg) {
  153. //高级查询方法
  154. if (!arg) {
  155. this.superQueryParams = ''
  156. this.superQueryFlag = false
  157. } else {
  158. this.superQueryFlag = true
  159. this.superQueryParams = JSON.stringify(arg)
  160. }
  161. this.loadData()
  162. },
  163. editDate(value) {
  164. let date = new Date(value)
  165. let y = date.getFullYear()
  166. let MM = date.getMonth() + 1
  167. MM = MM < 10 ? '0' + MM : MM
  168. let d = date.getDate()
  169. d = d < 10 ? '0' + d : d
  170. return y + '-' + MM + '-' + d
  171. },
  172. getQueryParams() {
  173. //获取查询条件
  174. let sqp = {}
  175. if (this.superQueryParams) {
  176. sqp['superQueryParams'] = encodeURI(this.superQueryParams)
  177. }
  178. // console.log(this.queryParam)
  179. var param = {...this.queryParam,...this.isorter, ...this.filters}
  180. param.pageNo = this.ipagination.current;
  181. param.pageSize = this.ipagination.pageSize;
  182. return param
  183. },
  184. getQueryField() {
  185. //TODO 字段权限控制
  186. var str = "id,";
  187. this.columns.forEach(function (value) {
  188. str += "," + value.dataIndex;
  189. });
  190. return str;
  191. },
  192. onSelectChange(selectedRowKeys, selectionRows) {
  193. this.selectedRowKeys = selectedRowKeys;
  194. this.selectionRows = selectionRows;
  195. },
  196. onClearSelected() {
  197. this.selectedRowKeys = [];
  198. this.selectionRows = [];
  199. },
  200. searchQuery() {
  201. this.loadData(1);
  202. },
  203. superQuery() {
  204. this.$refs.superQueryModal.show();
  205. },
  206. searchReset() {
  207. this.queryParam = {}
  208. this.loadData(1);
  209. },
  210. batchDel: function () {
  211. if (!this.url.deleteBatch) {
  212. this.$message.error("请设置url.deleteBatch属性!")
  213. return
  214. }
  215. if (this.selectedRowKeys.length <= 0) {
  216. this.$message.warning('请选择一条记录!');
  217. return;
  218. } else {
  219. var ids = "";
  220. for (var a = 0; a < this.selectedRowKeys.length; a++) {
  221. ids += this.selectedRowKeys[a] + ",";
  222. }
  223. var that = this;
  224. this.$confirm({
  225. title: "确认删除",
  226. content: "是否删除选中数据?",
  227. onOk: function () {
  228. deleteAction(that.url.deleteBatch, {ids: ids}).then((res) => {
  229. if (res.success) {
  230. that.$message.success(res.message);
  231. that.loadData();
  232. that.onClearSelected();
  233. } else {
  234. that.$message.warning(res.message);
  235. }
  236. });
  237. }
  238. });
  239. }
  240. },
  241. handleDelete: function (id) {
  242. if (!this.url.delete) {
  243. this.$message.error("请设置url.delete属性!")
  244. return
  245. }
  246. var that = this;
  247. deleteAction(that.url.delete, {id: id}).then((res) => {
  248. if (res.success) {
  249. that.$message.success(res.message);
  250. that.loadData();
  251. } else {
  252. that.$message.warning(res.message);
  253. }
  254. });
  255. },
  256. handleEdit: function (record,sign) {
  257. // console.log(record,sign)
  258. this.$refs.modalForm.edit(record,sign);
  259. this.$refs.modalForm.title = "编辑";
  260. this.$refs.modalForm.disableSubmit = false;
  261. if(sign == 'preview'){
  262. this.$refs.modalForm.title = "预览";
  263. }
  264. },
  265. handleImagePreview: function (record) {
  266. this.$refs.modalForm.imagePreview(record);
  267. this.$refs.modalForm.title = "预览";
  268. this.$refs.modalForm.disableSubmit = false;
  269. },
  270. handleAdd: function (sign) {
  271. this.$refs.modalForm.add(sign);
  272. this.$refs.modalForm.title = "新增";
  273. this.$refs.modalForm.disableSubmit = false;
  274. },
  275. handleOpen: function () {
  276. this.$refs.userForm.open();
  277. this.$refs.userForm.title = "选择";
  278. this.$refs.userForm.disableSubmit = false;
  279. },
  280. handleTableChange(pagination, filters, sorter) {
  281. //分页、排序、筛选变化时触发
  282. //TODO 筛选
  283. if (Object.keys(sorter).length > 0) {
  284. this.isorter.column = sorter.field;
  285. this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
  286. }
  287. this.ipagination = pagination;
  288. this.loadData();
  289. },
  290. handleToggleSearch() {
  291. this.toggleSearchStatus = !this.toggleSearchStatus;
  292. },
  293. modalFormOk() {
  294. // 新增/修改 成功时,重载列表
  295. this.loadData(1);
  296. },
  297. handleDetail: function (record) {
  298. this.$refs.modalForm.edit(record);
  299. this.$refs.modalForm.title = "详情";
  300. this.$refs.modalForm.disableSubmit = true;
  301. },
  302. /* 导出 */
  303. handleExportXls2() {
  304. let paramsStr = encodeURI(JSON.stringify(this.getQueryParams()));
  305. let url = `${window._CONFIG['domianURL']}/${this.url.exportXlsUrl}?paramsStr=${paramsStr}`;
  306. window.location.href = url;
  307. },
  308. handleExportXls(fileName) {
  309. if (!fileName || typeof fileName != "string") {
  310. fileName = "导出文件"
  311. }
  312. let param = {...this.queryParam};
  313. if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
  314. param['selections'] = this.selectedRowKeys.join(",")
  315. }
  316. // console.log("导出参数", param)
  317. downFile(this.url.exportXlsUrl, param).then((data) => {
  318. if (!data) {
  319. this.$message.warning("文件下载失败")
  320. return
  321. }
  322. if (typeof window.navigator.msSaveBlob !== 'undefined') {
  323. window.navigator.msSaveBlob(new Blob([data]), fileName + '.xls')
  324. } else {
  325. let url = window.URL.createObjectURL(new Blob([data]))
  326. let link = document.createElement('a')
  327. link.style.display = 'none'
  328. link.href = url
  329. link.setAttribute('download', fileName + '.xls')
  330. document.body.appendChild(link)
  331. link.click()
  332. document.body.removeChild(link); //下载完成移除元素
  333. window.URL.revokeObjectURL(url); //释放掉blob对象
  334. }
  335. })
  336. },
  337. /* 导入 */
  338. handleImportExcel(info) {
  339. if (info.file.status !== 'uploading') {
  340. // console.log(info.file, info.fileList);
  341. }
  342. if (info.file.status === 'done') {
  343. if (info.file.response.success) {
  344. this.$message.success(`${info.file.name} 文件上传成功`);
  345. this.loadData();
  346. } else {
  347. this.$message.error(`${info.file.name} ${info.file.response.message}.`);
  348. }
  349. } else if (info.file.status === 'error') {
  350. this.$message.error(`文件上传失败: ${info.file.msg} `);
  351. }
  352. },
  353. /* 图片预览 */
  354. getImgView(text) {
  355. if (text && text.indexOf(",") > 0) {
  356. text = text.substring(0, text.indexOf(","))
  357. }
  358. return window._CONFIG['imgDomainURL'] + "/" + text
  359. },
  360. /* 文件下载 */
  361. uploadFile(text) {
  362. if (!text) {
  363. this.$message.warning("未知的文件")
  364. return;
  365. }
  366. if (text.indexOf(",") > 0) {
  367. text = text.substring(0, text.indexOf(","))
  368. }
  369. window.open(window._CONFIG['domianURL'] + "/sys/common/download/" + text);
  370. },
  371. }
  372. }