JeecgListMixin.js 12 KB

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