You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
7.4 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. import Vue from 'vue'
  2. import App from '@/App'
  3. import router from '@/router' // api: https://github.com/vuejs/vue-router
  4. import store from '@/store' // api: https://github.com/vuejs/vuex
  5. import VueCookie from 'vue-cookie' // api: https://github.com/alfhen/vue-cookie // 时间处理
  6. import { isAuth } from '@/utils'
  7. import dayjs from 'dayjs';
  8. import '@/element-ui' // api: https://github.com/ElemeFE/element
  9. import '@/icons' // api: http://www.iconfont.cn/
  10. import '@/element-ui-theme'
  11. import 'element-ui/lib/theme-chalk/icon.css'
  12. import '@/assets/scss/index.scss'
  13. import httpRequest from '@/utils/httpRequest' // api: https://github.com/axios/axios
  14. import { searchUserSettingRecording } from '@/api/sift/queryUserSetting'
  15. import Ajax from "./utils/ajax.js";
  16. import cloneDeep from 'lodash/cloneDeep'
  17. import JsonExcel from 'vue-json-excel'
  18. import i18n from '@/i18n/i18n'
  19. import './utils/directives'
  20. import decimalUtil from '@/utils/decimalUtil.js'
  21. import getLodop from '@/utils/LodopFuncs.js'
  22. // import pdf from 'vue-pdf'
  23. import { debounce,throttle} from '@/utils/common.js'
  24. import 'element-ui/lib/theme-chalk/drawer.css';
  25. import 'element-ui/lib/theme-chalk/descriptions.css';
  26. import 'element-ui/lib/theme-chalk/popover.css';
  27. import Viewer from 'v-viewer'
  28. import 'viewerjs/dist/viewer.css'
  29. import selectDiv from '@/views/common/selectDiv.vue'
  30. import resizable from '@/utils/resizable.js'
  31. Vue.prototype.isAuth = isAuth // 权限方法
  32. Vue.component('downloadExcel', JsonExcel)
  33. // Vue.component('pdf', pdf)
  34. Vue.use(VueCookie)
  35. Vue.config.productionTip = false
  36. Vue.component('selectDiv', selectDiv);
  37. export const EventBus = new Vue();
  38. Vue.use(Viewer)
  39. Vue.directive('resizable',resizable)
  40. // 非生产环境, 适配mockjs模拟数据 // api: https://github.com/nuysoft/Mock
  41. if (process.env.NODE_ENV !== 'production') {
  42. require('@/mock')
  43. }
  44. // 挂载全局
  45. Vue.prototype.$http = httpRequest // ajax请求方法
  46. Vue.prototype.getLodop = getLodop // 打印
  47. Vue.prototype.decimalUtil = decimalUtil // 计算
  48. Vue.prototype.dayjs = dayjs //时间格式化插件 2021-11-02
  49. Vue.prototype.debounce = debounce // 防抖
  50. Vue.prototype.throttle = throttle // 限流
  51. window.ajax = Ajax;
  52. // 保存整站vuex本地储存初始状态
  53. window.SITE_CONFIG['storeState'] = cloneDeep(store.state)
  54. function extractRows (data) {
  55. if (!data) {
  56. return []
  57. }
  58. if (Array.isArray(data.rows)) {
  59. return data.rows
  60. }
  61. if (Array.isArray(data.list)) {
  62. return data.list
  63. }
  64. if (Array.isArray(data.data)) {
  65. return data.data
  66. }
  67. return []
  68. }
  69. function pickFormulaValue (row) {
  70. var formula = row && row.formula ? String(row.formula) : ''
  71. var symbol = row && row.symbol ? String(row.symbol).toLowerCase() : ''
  72. if (!formula) {
  73. return ''
  74. }
  75. if (symbol === 'between') {
  76. return formula.split('..')[0] || ''
  77. }
  78. if (symbol === 'in' || symbol === 'ne') {
  79. return formula
  80. }
  81. return formula
  82. }
  83. function buildAdvancedContextStorageKey (path) {
  84. return 'advanced_search_context_' + String(path || '')
  85. }
  86. function normalizeRoutePath (path) {
  87. var p = String(path || '').trim()
  88. if (!p) {
  89. return ''
  90. }
  91. if (p.charAt(0) !== '/') {
  92. p = '/' + p
  93. }
  94. return p
  95. }
  96. function parseAdvancedContextByPath (path) {
  97. var normalizedPath = normalizeRoutePath(path)
  98. var raw = sessionStorage.getItem(buildAdvancedContextStorageKey(normalizedPath))
  99. if (!raw && normalizedPath.indexOf('/modules/') === 0) {
  100. raw = sessionStorage.getItem(buildAdvancedContextStorageKey(normalizedPath.substring('/modules'.length)))
  101. }
  102. if (!raw && normalizedPath.indexOf('/modules/') !== 0) {
  103. raw = sessionStorage.getItem(buildAdvancedContextStorageKey('/modules' + normalizedPath))
  104. }
  105. if (!raw) {
  106. return null
  107. }
  108. try {
  109. var context = JSON.parse(raw)
  110. if (!context || !Array.isArray(context.conditions) || context.conditions.length <= 0) {
  111. return null
  112. }
  113. return context
  114. } catch (e) {
  115. return null
  116. }
  117. }
  118. Vue.mixin({
  119. mounted () {
  120. this.__applySavedRuleFromRoute()
  121. },
  122. activated () {
  123. this.__applySavedRuleFromRoute()
  124. },
  125. methods: {
  126. async __applySavedRuleFromRoute () {
  127. if (!this || !this.$route || !this.$route.query) {
  128. return
  129. }
  130. // 模块已实现专用恢复逻辑时,避免全局逻辑重复执行
  131. if (typeof this.searchTableBySavedRule === 'function') {
  132. return
  133. }
  134. var queryModel = this.searchData || this.queryHeaderData
  135. if (!queryModel) {
  136. return
  137. }
  138. if (typeof this.searchTable !== 'function' && typeof this.getDataList !== 'function') {
  139. return
  140. }
  141. var routeQuery = this.$route.query
  142. var routePath = normalizeRoutePath(this.$route.path || '')
  143. var menuId = routeQuery.menuId
  144. var itemNo = routeQuery.itemNo
  145. if (!menuId || !itemNo) {
  146. return
  147. }
  148. var cacheKey = [this.$route.path || '', menuId, itemNo].join('_')
  149. if (this.__savedRuleAppliedKey === cacheKey) {
  150. return
  151. }
  152. var existContext = parseAdvancedContextByPath(routePath)
  153. if (existContext) {
  154. this.__savedRuleAppliedKey = cacheKey
  155. return
  156. }
  157. try {
  158. var userId = String((this.$store && this.$store.state && this.$store.state.user && this.$store.state.user.id) || '')
  159. if (!userId) {
  160. return
  161. }
  162. var resp = await searchUserSettingRecording({
  163. menuId: String(menuId),
  164. userId: userId,
  165. itemNo: Number(itemNo)
  166. })
  167. var data = resp && resp.data ? resp.data : {}
  168. if (!(data && data.code === 0)) {
  169. return
  170. }
  171. var rows = extractRows(data)
  172. if (!rows.length) {
  173. return
  174. }
  175. try {
  176. var contextRows = rows
  177. .filter(row => row && row.fieldName && row.symbol && row.formula)
  178. .map(row => ({
  179. fieldName: String(row.fieldName),
  180. symbol: String(row.symbol).toLowerCase(),
  181. formula: String(row.formula)
  182. }))
  183. sessionStorage.setItem(buildAdvancedContextStorageKey(routePath), JSON.stringify({
  184. menuUrl: routePath,
  185. conditions: contextRows
  186. }))
  187. } catch (e) {
  188. }
  189. if (Object.prototype.hasOwnProperty.call(this, 'pageIndex')) {
  190. this.pageIndex = 1
  191. }
  192. this.__savedRuleAppliedKey = cacheKey
  193. if (typeof this.searchTable === 'function') {
  194. this.searchTable()
  195. } else if (typeof this.getDataList === 'function') {
  196. try {
  197. this.getDataList('Y')
  198. } catch (e) {
  199. this.getDataList()
  200. }
  201. }
  202. } catch (e) {
  203. } finally {
  204. var query = Object.assign({}, routeQuery)
  205. delete query.savedSearchId
  206. delete query.menuId
  207. delete query.itemNo
  208. if (this.$router && typeof this.$router.replace === 'function') {
  209. var result = this.$router.replace({
  210. path: this.$route.path,
  211. query: query
  212. })
  213. if (result && typeof result.catch === 'function') {
  214. result.catch(() => {})
  215. }
  216. }
  217. }
  218. }
  219. }
  220. })
  221. /* eslint-disable no-new */
  222. new Vue({
  223. el: '#app',
  224. router,
  225. i18n,
  226. store,
  227. template: '<App/>',
  228. components: { App }
  229. })
  230. Viewer.setDefaults({
  231. // 需要配置的属性 注意属性并没有引号
  232. title: false,
  233. toolbar: true,
  234. zIndex: 99999,
  235. })