JeecgListMixin.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. console.log(res)
  87. //update-begin---author:zhangyafei Date:20201118 for:适配不分页的数据列表------------
  88. this.dataSource = res.result.records||res.result;
  89. this.dataSource.forEach((item)=>{
  90. if(item.gyzccgbl){
  91. item.gyzccgbl=Number( item.gyzccgbl).toFixed(2)
  92. }
  93. })
  94. if(res.result.total)
  95. {
  96. this.ipagination.total = res.result.total;
  97. }else{
  98. this.ipagination.total = 0;
  99. }
  100. //update-end---author:zhangyafei Date:20201118 for:适配不分页的数据列表------------
  101. }else{
  102. this.$message.warning(res.message)
  103. }
  104. }).finally(() => {
  105. this.loading = false
  106. })
  107. },
  108. initDictConfig(){
  109. console.log("--这是一个假的方法!")
  110. },
  111. handleSuperQuery(params, matchType) {
  112. //高级查询方法
  113. if(!params){
  114. this.superQueryParams=''
  115. this.superQueryFlag = false
  116. }else{
  117. this.superQueryFlag = true
  118. this.superQueryParams=JSON.stringify(params)
  119. this.superQueryMatchType = matchType
  120. }
  121. this.loadData(1)
  122. },
  123. getQueryParams() {
  124. //获取查询条件
  125. let sqp = {}
  126. if(this.superQueryParams){
  127. sqp['superQueryParams']=encodeURI(this.superQueryParams)
  128. sqp['superQueryMatchType'] = this.superQueryMatchType
  129. }
  130. // 参数去空
  131. if (Object.prototype.toString.call(this.queryParam) === "[object Object]") {
  132. for (let paramKey in this.queryParam) {
  133. this.queryParam[paramKey] = typeof this.queryParam[paramKey] === "string" ? this.queryParam[paramKey].trim() : this.queryParam[paramKey];
  134. }
  135. }
  136. var param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);
  137. param.field = this.getQueryField();
  138. param.pageNo = this.ipagination.current;
  139. param.pageSize = this.ipagination.pageSize;
  140. return filterObj(param);
  141. },
  142. getQueryField() {
  143. //TODO 字段权限控制
  144. var str = "id,";
  145. this.columns.forEach(function (value) {
  146. str += "," + value.dataIndex;
  147. });
  148. return str;
  149. },
  150. onSelectChange(selectedRowKeys, selectionRows) {
  151. this.selectedRowKeys = selectedRowKeys;
  152. this.selectionRows = selectionRows;
  153. },
  154. onClearSelected() {
  155. this.selectedRowKeys = [];
  156. this.selectionRows = [];
  157. },
  158. searchQuery() {
  159. this.loadData(1);
  160. // 点击查询清空列表选中行
  161. // https://gitee.com/jeecg/jeecg-boot/issues/I4KTU1
  162. this.selectedRowKeys = []
  163. this.selectionRows = []
  164. },
  165. superQuery() {
  166. this.$refs.superQueryModal.show();
  167. },
  168. searchReset() {
  169. this.queryParam = {}
  170. this.loadData(1);
  171. },
  172. batchDel: function () {
  173. if(!this.url.deleteBatch){
  174. this.$message.error("请设置url.deleteBatch属性!")
  175. return
  176. }
  177. if (this.selectedRowKeys.length <= 0) {
  178. this.$message.warning('请选择一条记录!');
  179. return;
  180. } else {
  181. var ids = "";
  182. for (var a = 0; a < this.selectedRowKeys.length; a++) {
  183. ids += this.selectedRowKeys[a] + ",";
  184. }
  185. var that = this;
  186. this.$confirm({
  187. title: "确认删除",
  188. content: "是否删除选中数据?",
  189. onOk: function () {
  190. that.loading = true;
  191. deleteAction(that.url.deleteBatch, {ids: ids}).then((res) => {
  192. if (res.success) {
  193. //重新计算分页问题
  194. that.reCalculatePage(that.selectedRowKeys.length)
  195. that.$message.success(res.message);
  196. that.loadData();
  197. that.onClearSelected();
  198. } else {
  199. that.$message.warning(res.message);
  200. }
  201. }).finally(() => {
  202. that.loading = false;
  203. });
  204. }
  205. });
  206. }
  207. },
  208. handleDelete: function (id) {
  209. if(!this.url.delete){
  210. this.$message.error("请设置url.delete属性!")
  211. return
  212. }
  213. var that = this;
  214. deleteAction(that.url.delete, {id: id}).then((res) => {
  215. if (res.success) {
  216. //重新计算分页问题
  217. that.reCalculatePage(1)
  218. that.$message.success(res.message);
  219. that.loadData();
  220. } else {
  221. that.$message.warning(res.message);
  222. }
  223. });
  224. },
  225. reCalculatePage(count){
  226. //总数量-count
  227. let total=this.ipagination.total-count;
  228. //获取删除后的分页数
  229. let currentIndex=Math.ceil(total/this.ipagination.pageSize);
  230. //删除后的分页数<所在当前页
  231. if(currentIndex<this.ipagination.current){
  232. this.ipagination.current=currentIndex;
  233. }
  234. console.log('currentIndex',currentIndex)
  235. },
  236. handleEdit: function (record) {
  237. this.$refs.modalForm.edit(record);
  238. this.$refs.modalForm.title = "编辑";
  239. this.$refs.modalForm.disableSubmit = false;
  240. },
  241. handleEdit1: function (record) {
  242. this.$refs.modalForm.edit1(record);
  243. this.$refs.modalForm.title = "变更";
  244. this.$refs.modalForm.disableSubmit = false;
  245. },
  246. handleAdd: function () {
  247. this.$refs.modalForm.add();
  248. this.$refs.modalForm.title = "新增";
  249. this.$refs.modalForm.disableSubmit = false;
  250. },
  251. handleAdd2: function () {
  252. getAction("/qcsb/qcSsgqzysytdqk/selectQyxx").then(res=>{
  253. if(res.result==null){
  254. this.$message.warn("请先补全用地单位信息并上报!")
  255. }else
  256. if(res.result.sfsjtdzc=='是'){
  257. this.$refs.modalForm.add();
  258. this.$refs.modalForm.title = "新增";
  259. this.$refs.modalForm.uploads=true;
  260. this.$refs.modalForm.disableSubmit = false;
  261. }else if(res.result.sfsjtdzc=='否'){
  262. this.$message.warn("未涉及省内土地资产!")
  263. }
  264. })
  265. },
  266. handleTableChange(pagination, filters, sorter) {
  267. //分页、排序、筛选变化时触发
  268. //TODO 筛选
  269. console.log(pagination)
  270. if (Object.keys(sorter).length > 0) {
  271. this.isorter.column = sorter.field;
  272. this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
  273. }
  274. this.ipagination = pagination;
  275. this.loadData();
  276. },
  277. handleToggleSearch(){
  278. this.toggleSearchStatus = !this.toggleSearchStatus;
  279. },
  280. // 给popup查询使用(查询区域不支持回填多个字段,限制只返回一个字段)
  281. getPopupField(fields){
  282. return fields.split(',')[0]
  283. },
  284. modalFormOk() {
  285. // 新增/修改 成功时,重载列表
  286. this.loadData();
  287. //清空列表选中
  288. this.onClearSelected()
  289. },
  290. handleDetail:function(record){
  291. this.$refs.modalForm.edit(record);
  292. this.$refs.modalForm.title="详情";
  293. this.$refs.modalForm.uploads=false;
  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 (this.dataSource.length == 0) {
  304. /*this.$notification.error({
  305. message: '提示',
  306. description: `无相关记录,不支持导出!`,
  307. duration:3
  308. })*/
  309. this.$message.error("无相关记录,不支持导出!")
  310. return
  311. }
  312. if(!fileName || typeof fileName != "string"){
  313. fileName = "导出文件"
  314. }
  315. let param = this.getQueryParams();
  316. if(this.selectedRowKeys && this.selectedRowKeys.length>0){
  317. param['selections'] = this.selectedRowKeys.join(",")
  318. }
  319. console.log("导出参数",param)
  320. downFile(this.url.exportXlsUrl,param).then((data)=>{
  321. if (!data) {
  322. this.$message.warning("文件下载失败")
  323. return
  324. }
  325. if (typeof window.navigator.msSaveBlob !== 'undefined') {
  326. window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')
  327. }else{
  328. let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
  329. let link = document.createElement('a')
  330. link.style.display = 'none'
  331. link.href = url
  332. link.setAttribute('download', fileName+'.xls')
  333. document.body.appendChild(link)
  334. link.click()
  335. document.body.removeChild(link); //下载完成移除元素
  336. window.URL.revokeObjectURL(url); //释放掉blob对象
  337. }
  338. })
  339. },
  340. /* 导入 */
  341. handleImportExcel(info){
  342. this.loading = true;
  343. if (info.file.status !== 'uploading') {
  344. console.log(info.file, info.fileList);
  345. }
  346. if (info.file.status === 'done') {
  347. this.loading = false;
  348. if (info.file.response.success) {
  349. // this.$message.success(`${info.file.name} 文件上传成功`);
  350. if (info.file.response.code === 201) {
  351. let { message, result: { msg, fileUrl, fileName } } = info.file.response
  352. let href = window._CONFIG['domianURL'] + fileUrl
  353. this.$warning({
  354. title: message,
  355. content: (<div>
  356. <span>{msg}</span><br/>
  357. <span>具体详情请 <a href={href} target="_blank" download={fileName}>点击下载</a> </span>
  358. </div>
  359. )
  360. })
  361. } else {
  362. this.$message.success(info.file.response.message || `${info.file.name} 文件上传成功`)
  363. }
  364. this.loadData()
  365. } else {
  366. this.$message.error(`${info.file.name} ${info.file.response.message}.`);
  367. }
  368. } else if (info.file.status === 'error') {
  369. this.loading = false;
  370. if (info.file.response.status === 500) {
  371. let data = info.file.response
  372. const token = Vue.ls.get(ACCESS_TOKEN)
  373. if (token && data.message.includes("Token失效")) {
  374. this.$error({
  375. title: '登录已过期',
  376. content: '很抱歉,登录已过期,请重新登录',
  377. okText: '重新登录',
  378. mask: false,
  379. onOk: () => {
  380. store.dispatch('Logout').then(() => {
  381. Vue.ls.remove(ACCESS_TOKEN)
  382. window.location.reload();
  383. })
  384. }
  385. })
  386. }
  387. } else {
  388. this.$message.error(`文件上传失败: ${info.file.msg} `);
  389. }
  390. }
  391. },
  392. /* 图片预览 */
  393. getImgView(text){
  394. if(text && text.indexOf(",")>0){
  395. text = text.substring(0,text.indexOf(","))
  396. }
  397. return getFileAccessHttpUrl(text)
  398. },
  399. /* 文件下载 */
  400. // update--autor:lvdandan-----date:20200630------for:修改下载文件方法名uploadFile改为downloadFile------
  401. downloadFile(text){
  402. if(!text){
  403. this.$message.warning("未知的文件")
  404. return;
  405. }
  406. if(text.indexOf(",")>0){
  407. text = text.substring(0,text.indexOf(","))
  408. }
  409. let url = getFileAccessHttpUrl(text)
  410. window.open(url);
  411. },
  412. previewPdfFile(text) {
  413. if (!text) {
  414. this.$message.warning("未知的文件")
  415. return;
  416. }
  417. if (text.indexOf(",") > 0) {
  418. text = text.substring(0, text.indexOf(","))
  419. }
  420. let fileUrl = window._CONFIG['domianURL'] + '/' + text;
  421. let pdfUrl = window._CONFIG['domianURL'] + "/generic/web/viewer.html?file=" + encodeURIComponent(fileUrl);
  422. window.open(pdfUrl, "_blank");
  423. }
  424. }
  425. }