JeecgListMixin.js 11 KB

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