JeecgListMixin.js 12 KB

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