main.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import Vue from 'vue'
  2. import App from './App'
  3. import store from './store'
  4. import globalMixin from './mixin/global'
  5. Vue.config.productionTip = false
  6. // echar引入
  7. import * as echarts from 'echarts'
  8. Vue.prototype.$echarts = echarts
  9. Vue.prototype.$baseImgUrl = 'https://www.tuanfengkeji.cn:9527/dts-admin-api/admin/storage/fetch/'
  10. Vue.filter('replacestar', function (value) {
  11. if (!value) return ''
  12. let str = value
  13. str = str.replace(new RegExp('[^0-9]+', 'g'), '')
  14. if (str.length == 11) {
  15. str = str.toString().replace(/(\d{3})\d*(\d{4})/, '$1****$2')
  16. } else {
  17. str = str.toString().replace(/(\d{3})\d*(\d{4})/, '$1****$2')
  18. }
  19. return str
  20. })
  21. Vue.mixin({
  22. data() {
  23. return {
  24. common: {
  25. seamingImgUrl(url) {
  26. if (!url) return ''
  27. // return url.startsWith('https://') ? url : 'https://www.tuanfengkeji.cn:9527/dts-admin-api/admin/storage/fetch/' + url
  28. if (url.startsWith('http://')) {
  29. return url.replace('http://', 'https://')
  30. } else if (url.startsWith('https://')) {
  31. return url
  32. } else if (url.startsWith('//')) {
  33. return 'https:' + url
  34. }
  35. // https://tuanfengkeji.oss-cn-beijing.aliyuncs.com/tfshop/
  36. // https://jufeng-shop-1317254189.cos.ap-guangzhou.myqcloud.com/
  37. return 'https://tuanfengkeji.oss-cn-beijing.aliyuncs.com/tfshop/' + url
  38. }
  39. }
  40. }
  41. },
  42. methods: {
  43. setData(obj) {
  44. const that = this
  45. let keys = []
  46. let val, data
  47. Object.keys(obj).forEach(function (key) {
  48. keys = key.split('.')
  49. val = obj[key]
  50. data = that.$data
  51. keys.forEach(function (key2, index) {
  52. if (index + 1 == keys.length) {
  53. that.$set(data, key2, val)
  54. } else if (!data[key2]) {
  55. that.$set(data, key2, {})
  56. }
  57. data = data[key2]
  58. })
  59. })
  60. },
  61. $showToast(text, icon) {
  62. uni.showToast({
  63. title: text,
  64. duration: 2000,
  65. icon: icon || 'none'
  66. })
  67. },
  68. go(url, param) {
  69. if (!url) return
  70. if (param) url = `${url}?detail=${encodeURIComponent(JSON.stringify(param)?.replace(/%/g, '%25'))}`
  71. uni.navigateTo({
  72. url
  73. })
  74. },
  75. $getJumpParam(loadParam) {
  76. if (typeof loadParam === 'object' && loadParam?.detail) return JSON.parse(decodeURIComponent(loadParam.detail))
  77. return {}
  78. },
  79. $copy(text, title = '复制成功') {
  80. uni.setClipboardData({
  81. data: text,
  82. success: () => {
  83. uni.showToast({
  84. title
  85. })
  86. }
  87. })
  88. },
  89. $redirectTo(url) {
  90. if (!url) return
  91. uni.redirectTo({ url })
  92. },
  93. $switchTab(url) {
  94. if (!url) return
  95. uni.switchTab({ url })
  96. },
  97. getSize(selecter) {
  98. const _this = this
  99. return new Promise((resolve, reject) => {
  100. const query = uni.createSelectorQuery().in(_this)
  101. query
  102. .select(selecter)
  103. .boundingClientRect((data) => {
  104. resolve(data)
  105. })
  106. .exec()
  107. })
  108. },
  109. empty() {
  110. uni.showToast({
  111. title: '功能升级中...',
  112. icon: 'none'
  113. })
  114. },
  115. isLogin() {
  116. return !!(this.$store.getters.userInfo && this.$store.getters.userInfo.token)
  117. }
  118. }
  119. })
  120. Vue.use(globalMixin)
  121. Vue.config.ignoredElements.push('wx-open-launch-weapp')
  122. App.mpType = 'app'
  123. const app = new Vue({
  124. ...App,
  125. store
  126. })
  127. app.$mount()
  128. // import filters from './utils/filter' // 导入过滤器文件
  129. // Object.keys(filters).forEach((key) => {
  130. // // 通过Object.key方法取出过滤器中导出的每个方法并挂在vue.filter上
  131. // Vue.filter(key, filters[key])
  132. // })