main.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import Vue from 'vue'
  2. import App from './App'
  3. import store from './store/index.js'
  4. import uView from 'uview-ui'
  5. Vue.mixin({
  6. data() {
  7. return {
  8. common: {
  9. seamingImgUrl(url) {
  10. if (!url) return ''
  11. return url.startsWith('https://') ? url : 'https://www.tuanfengkeji.cn:9527/dts-admin-api/admin/storage/fetch/' + url
  12. }
  13. }
  14. }
  15. },
  16. methods: {
  17. setData(obj) {
  18. const that = this
  19. let keys = []
  20. let val, data
  21. Object.keys(obj).forEach(function (key) {
  22. keys = key.split('.')
  23. val = obj[key]
  24. data = that.$data
  25. keys.forEach(function (key2, index) {
  26. if (index + 1 == keys.length) {
  27. that.$set(data, key2, val)
  28. } else if (!data[key2]) {
  29. that.$set(data, key2, {})
  30. }
  31. data = data[key2]
  32. })
  33. })
  34. },
  35. $showToast(text, icon) {
  36. uni.showToast({
  37. title: text,
  38. duration: 2000,
  39. icon: icon || 'none'
  40. })
  41. },
  42. go(url, param) {
  43. if (!url) return
  44. if (param) url = `${url}?detail=${encodeURIComponent(JSON.stringify(param)?.replace(/%/g, '%25'))}`
  45. uni.navigateTo({
  46. url
  47. })
  48. },
  49. $getJumpParam(loadParam) {
  50. if (typeof loadParam === 'object' && loadParam?.detail) return JSON.parse(decodeURIComponent(loadParam.detail))
  51. return {}
  52. },
  53. $copy(text, title = '复制成功') {
  54. uni.setClipboardData({
  55. data: text,
  56. success: () => {
  57. uni.showToast({
  58. title
  59. })
  60. }
  61. })
  62. },
  63. $redirectTo(url) {
  64. if (!url) return
  65. uni.redirectTo({ url })
  66. },
  67. $switchTab(url) {
  68. if (!url) return
  69. uni.switchTab({ url })
  70. },
  71. getSize(selecter) {
  72. const _this = this
  73. return new Promise((resolve, reject) => {
  74. const query = uni.createSelectorQuery().in(_this)
  75. query
  76. .select(selecter)
  77. .boundingClientRect((data) => {
  78. resolve(data)
  79. })
  80. .exec()
  81. })
  82. },
  83. empty() {
  84. uni.showToast({
  85. title: '功能升级中...',
  86. icon: 'none'
  87. })
  88. },
  89. isLogin() {
  90. return !!this.$store.state.userId
  91. }
  92. }
  93. })
  94. Vue.use(uView)
  95. Vue.config.productionTip = false
  96. App.mpType = 'app'
  97. const app = new Vue({
  98. ...App,
  99. store
  100. })
  101. app.$mount()