JeecgListMixin.js 12 KB

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