488bf4cc3c3b8af830c3007c87edd054218e974a.svn-base 15 KB

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