JeecgListMixin.js 9.0 KB

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