@dcloudio/uni-h5 2.0.0 → 2.0.1-32920211122002

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/dist/automator.js +1 -1
  2. package/dist/index.css +1 -1
  3. package/dist/index.umd.min.js +1 -1
  4. package/lib/apis.js +14 -4
  5. package/lib/h5/uni.automator.js +1 -1
  6. package/lib/modules.json +4 -1
  7. package/manifest.json +49 -0
  8. package/package.json +2 -3
  9. package/src/core/helpers/api.js +1 -1
  10. package/src/core/helpers/constants.js +1 -0
  11. package/src/core/helpers/i18n/en.json +4 -2
  12. package/src/core/helpers/i18n/es.json +4 -1
  13. package/src/core/helpers/i18n/fr.json +4 -1
  14. package/src/core/helpers/i18n/index.js +155 -4
  15. package/src/core/helpers/i18n/zh-Hans.json +4 -1
  16. package/src/core/helpers/i18n/zh-Hant.json +4 -1
  17. package/src/core/helpers/index.js +1 -1
  18. package/src/core/helpers/interceptor.js +19 -15
  19. package/src/core/helpers/promise.js +1 -1
  20. package/src/core/helpers/protocol/device/set-clipboard-data.js +11 -2
  21. package/src/core/helpers/protocol/network/request.js +14 -1
  22. package/src/core/helpers/protocol/network/upload-file.js +1 -1
  23. package/src/core/helpers/protocol/ui/popup.js +2 -2
  24. package/src/core/runtime/base.js +2 -0
  25. package/src/core/runtime/locale.js +37 -0
  26. package/src/core/runtime/web-view/index.js +4 -0
  27. package/src/core/runtime/wrapper/create-subpackage-app.js +7 -6
  28. package/src/core/runtime/wrapper/util.js +6 -1
  29. package/src/core/service/api/base/interceptor.js +1 -1
  30. package/src/core/service/api/context/canvas.js +3 -2
  31. package/src/core/service/api/context/create-map-context.js +8 -1
  32. package/src/core/service/api/ui/locale.js +50 -0
  33. package/src/core/service/plugins/app/create-app.js +8 -3
  34. package/src/core/service/plugins/app/index.js +2 -2
  35. package/src/core/service/plugins/index.js +8 -2
  36. package/src/core/view/bridge/subscribe/api/request-component-observer.js +16 -1
  37. package/src/core/view/components/canvas/index.vue +3 -1
  38. package/src/core/view/components/editor/formats/image.js +3 -1
  39. package/src/core/view/components/editor/formats/index.js +3 -1
  40. package/src/core/view/components/editor/formats/link.js +9 -0
  41. package/src/core/view/components/editor/index.vue +33 -3
  42. package/src/core/view/components/image/index.vue +4 -5
  43. package/src/core/view/components/input/index.vue +53 -25
  44. package/src/core/view/components/picker-view-column/index.vue +1 -0
  45. package/src/core/view/components/progress/index.vue +20 -13
  46. package/src/core/view/components/rich-text/index.vue +13 -1
  47. package/src/core/view/components/rich-text/nodes-parser.js +23 -4
  48. package/src/core/view/components/scroll-view/index.vue +253 -122
  49. package/src/core/view/components/slider/index.vue +1 -1
  50. package/src/core/view/components/swiper/index.vue +3 -0
  51. package/src/core/view/components/textarea/index.vue +7 -3
  52. package/src/core/view/index.css +4 -0
  53. package/src/core/view/mixins/field.js +27 -9
  54. package/src/core/view/mixins/interact.js +13 -11
  55. package/src/core/view/mixins/keyboard.js +42 -26
  56. package/src/core/view/mixins/touchtrack.js +2 -2
  57. package/src/core/view/plugins/index.js +1 -1
  58. package/src/platforms/app-plus/constants.js +1 -0
  59. package/src/platforms/app-plus/helpers/get-real-path.js +7 -4
  60. package/src/platforms/app-plus/helpers/uuid.js +1 -1
  61. package/src/platforms/app-plus/service/api/ad/ad-base.js +159 -0
  62. package/src/platforms/app-plus/service/api/ad/ad.js +4 -8
  63. package/src/platforms/app-plus/service/api/ad/full-screen-video-ad.js +5 -98
  64. package/src/platforms/app-plus/service/api/ad/interactive-ad.js +257 -0
  65. package/src/platforms/app-plus/service/api/ad/interstitial-ad.js +15 -0
  66. package/src/platforms/app-plus/service/api/ad/rewarded-video-ad.js +15 -2
  67. package/src/platforms/app-plus/service/api/device/system.js +3 -2
  68. package/src/platforms/app-plus/service/api/file/open-document.js +7 -15
  69. package/src/platforms/app-plus/service/api/index.js +2 -0
  70. package/src/platforms/app-plus/service/api/location/get-location.js +8 -7
  71. package/src/platforms/app-plus/service/api/media/choose-image.js +22 -51
  72. package/src/platforms/app-plus/service/api/media/choose-video.js +19 -36
  73. package/src/platforms/app-plus/service/api/media/compress-video.js +2 -2
  74. package/src/platforms/app-plus/service/api/media/get-video-info.js +5 -2
  75. package/src/platforms/app-plus/service/api/network/request.js +27 -1
  76. package/src/platforms/app-plus/service/api/network/upload-file.js +1 -1
  77. package/src/platforms/app-plus/service/api/plugin/oauth.js +140 -8
  78. package/src/platforms/app-plus/service/api/storage/storage.js +1 -1
  79. package/src/platforms/app-plus/service/api/ui/popup.js +21 -11
  80. package/src/platforms/app-plus/service/api/ui/tab-bar.js +3 -2
  81. package/src/platforms/app-plus/service/api/util.js +5 -1
  82. package/src/platforms/app-plus/service/framework/app.js +21 -5
  83. package/src/platforms/app-plus/service/framework/config.js +1 -0
  84. package/src/platforms/app-plus/service/framework/plugins/index.js +8 -2
  85. package/src/platforms/app-plus/service/framework/plugins/lifecycle.js +2 -2
  86. package/src/platforms/app-plus/service/framework/subscribe-handlers/index.js +1 -1
  87. package/src/platforms/app-plus/service/framework/tab-bar.js +12 -2
  88. package/src/platforms/app-plus/service/framework/webview/index.js +2 -2
  89. package/src/platforms/app-plus/service/framework/webview/parser/title-nview-parser.js +73 -30
  90. package/src/platforms/app-plus/service/framework/webview/parser/webview-style-parser.js +16 -16
  91. package/src/platforms/app-plus/service/index.js +10 -3
  92. package/src/platforms/app-plus/service/publish-handler.js +3 -0
  93. package/src/platforms/app-plus/view/bridge/subscribe/index.js +5 -3
  94. package/src/platforms/app-plus/view/components/ad/index.vue +53 -44
  95. package/src/platforms/app-plus/view/components/cover-view/index.vue +13 -7
  96. package/src/platforms/app-plus/view/components/map/index.vue +29 -27
  97. package/src/platforms/app-plus/view/components/video/index.vue +40 -24
  98. package/src/platforms/app-plus/view/framework/plugins/gesture.js +17 -0
  99. package/src/platforms/app-plus/view/framework/plugins/index.js +3 -1
  100. package/src/platforms/app-plus/view/index.css +4 -0
  101. package/src/platforms/app-plus/view/mixins/cover.js +10 -15
  102. package/src/platforms/app-plus/view/mixins/native.js +45 -3
  103. package/src/platforms/app-plus-nvue/service/api/context/operate-map-player.js +3 -0
  104. package/src/platforms/h5/components/app/observable.js +3 -2
  105. package/src/platforms/h5/components/app/popup/mixins/modal.js +3 -3
  106. package/src/platforms/h5/components/app/popup/modal.vue +38 -2
  107. package/src/platforms/h5/components/app/popup/toast.vue +9 -1
  108. package/src/platforms/h5/components/app/tabBar.vue +39 -17
  109. package/src/platforms/h5/components/page/index.vue +5 -3
  110. package/src/platforms/h5/components/page/pageHead.vue +94 -75
  111. package/src/platforms/h5/components/system-routes/choose-location/index.vue +127 -66
  112. package/src/platforms/h5/components/system-routes/open-location/index.vue +193 -38
  113. package/src/platforms/h5/helpers/location.js +26 -0
  114. package/src/platforms/h5/helpers/todo-api.js +2 -2
  115. package/src/platforms/h5/service/api/device/clipboard.js +41 -0
  116. package/src/platforms/h5/service/api/device/get-system-info.js +75 -0
  117. package/src/platforms/h5/service/api/location/get-location.js +47 -18
  118. package/src/platforms/h5/service/api/media/MIMEType.js +53 -0
  119. package/src/platforms/h5/service/api/media/choose-file.js +9 -1
  120. package/src/platforms/h5/service/api/media/choose-image.js +9 -2
  121. package/src/platforms/h5/service/api/media/choose-video.js +9 -1
  122. package/src/platforms/h5/service/api/media/create_input.js +12 -3
  123. package/src/platforms/h5/service/api/ui/popup.js +3 -5
  124. package/src/platforms/h5/service/api/ui/tab-bar.js +1 -1
  125. package/src/platforms/h5/service/index.js +5 -0
  126. package/src/platforms/h5/view/bridge/subscribe/index.js +3 -2
  127. package/src/platforms/h5/view/components/ad/index.vue +112 -69
  128. package/src/platforms/h5/view/components/map/index.vue +96 -349
  129. package/src/platforms/h5/view/components/map/map-marker.js +287 -0
  130. package/src/platforms/h5/view/components/map/maps/callout.js +117 -0
  131. package/src/platforms/h5/view/components/map/maps/index.js +55 -0
  132. package/src/platforms/h5/view/components/video/index.vue +1 -1
  133. package/src/platforms/h5/view/index.css +4 -0
  134. package/src/platforms/mp-alipay/runtime/api/protocols.js +30 -3
  135. package/src/platforms/mp-baidu/runtime/api/protocols.js +5 -0
  136. package/src/platforms/mp-baidu/runtime/wrapper/component-parser.js +20 -18
  137. package/src/platforms/mp-baidu/runtime/wrapper/util.js +2 -1
  138. package/src/platforms/mp-kuaishou/runtime/api/protocols.js +3 -1
  139. package/src/platforms/mp-kuaishou/runtime/wrapper/component-parser.js +21 -1
  140. package/src/platforms/mp-lark/runtime/api/index.js +0 -0
  141. package/src/platforms/mp-lark/runtime/api/protocols.js +68 -0
  142. package/src/platforms/mp-lark/runtime/api/providers.js +6 -0
  143. package/src/platforms/mp-lark/runtime/index.js +1 -0
  144. package/src/platforms/mp-lark/runtime/web-view.js +11 -0
  145. package/src/platforms/mp-lark/runtime/wrapper/app-parser.js +33 -0
  146. package/src/platforms/mp-lark/runtime/wrapper/component-parser.js +50 -0
  147. package/src/platforms/mp-lark/runtime/wrapper/page-parser.js +39 -0
  148. package/src/platforms/mp-lark/runtime/wrapper/util.js +64 -0
  149. package/src/platforms/mp-qq/runtime/api/protocols.js +3 -1
  150. package/src/platforms/mp-toutiao/runtime/api/protocols.js +2 -0
  151. package/src/platforms/mp-toutiao/runtime/wrapper/component-parser.js +35 -19
  152. package/src/platforms/mp-weixin/helpers/get-user-profile.js +6 -0
  153. package/src/platforms/mp-weixin/runtime/index.js +6 -7
  154. package/src/platforms/mp-weixin/runtime/wrapper/app-base-parser.js +197 -126
  155. package/src/platforms/mp-weixin/runtime/wrapper/fix-set-data.js +37 -0
  156. package/src/shared/uni-id-mixin.js +77 -0
  157. package/src/shared/util.js +2 -0
@@ -1,126 +1,197 @@
1
- import Vue from 'vue'
2
-
3
- import {
4
- initHooks,
5
- initMocks
6
- } from 'uni-wrapper/util'
7
-
8
- import EventChannel from 'uni-helpers/EventChannel'
9
-
10
- import {
11
- getEventChannel
12
- } from 'uni-helpers/navigate-to'
13
-
14
- const hooks = [
15
- 'onShow',
16
- 'onHide',
17
- 'onError',
18
- 'onPageNotFound',
19
- 'onThemeChange',
20
- 'onUnhandledRejection'
21
- ]
22
-
23
- function initEventChannel () {
24
- Vue.prototype.getOpenerEventChannel = function () {
25
- // 微信小程序使用自身getOpenerEventChannel
26
- if (__PLATFORM__ === 'mp-weixin') {
27
- return this.$scope.getOpenerEventChannel()
28
- }
29
- if (!this.__eventChannel__) {
30
- this.__eventChannel__ = new EventChannel()
31
- }
32
- return this.__eventChannel__
33
- }
34
- const callHook = Vue.prototype.__call_hook
35
- Vue.prototype.__call_hook = function (hook, args) {
36
- if (hook === 'onLoad' && args && args.__id__) {
37
- this.__eventChannel__ = getEventChannel(args.__id__)
38
- delete args.__id__
39
- }
40
- return callHook.call(this, hook, args)
41
- }
42
- }
43
-
44
- export default function parseBaseApp (vm, {
45
- mocks,
46
- initRefs
47
- }) {
48
- initEventChannel()
49
- if (vm.$options.store) {
50
- Vue.prototype.$store = vm.$options.store
51
- }
52
-
53
- Vue.prototype.mpHost = __PLATFORM__
54
-
55
- Vue.mixin({
56
- beforeCreate () {
57
- if (!this.$options.mpType) {
58
- return
59
- }
60
-
61
- this.mpType = this.$options.mpType
62
-
63
- this.$mp = {
64
- data: {},
65
- [this.mpType]: this.$options.mpInstance
66
- }
67
-
68
- this.$scope = this.$options.mpInstance
69
-
70
- delete this.$options.mpType
71
- delete this.$options.mpInstance
72
- if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
73
- const app = getApp()
74
- if (app.$vm && app.$vm.$i18n) {
75
- this._i18n = app.$vm.$i18n
76
- }
77
- }
78
- if (this.mpType !== 'app') {
79
- initRefs(this)
80
- initMocks(this, mocks)
81
- }
82
- }
83
- })
84
-
85
- const appOptions = {
86
- onLaunch (args) {
87
- if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
88
- return
89
- }
90
- if (__PLATFORM__ === 'mp-weixin' || __PLATFORM__ === 'mp-qq') {
91
- if (wx.canIUse && !wx.canIUse('nextTick')) { // 事实 上2.2.3 即可,简单使用 2.3.0 的 nextTick 判断
92
- console.error('当前微信基础库版本过低,请将 微信开发者工具-详情-项目设置-调试基础库版本 更换为`2.3.0`以上')
93
- }
94
- }
95
-
96
- this.$vm = vm
97
-
98
- this.$vm.$mp = {
99
- app: this
100
- }
101
-
102
- this.$vm.$scope = this
103
- // vm 上也挂载 globalData
104
- this.$vm.globalData = this.globalData
105
-
106
- this.$vm._isMounted = true
107
- this.$vm.__call_hook('mounted', args)
108
-
109
- this.$vm.__call_hook('onLaunch', args)
110
- }
111
- }
112
-
113
- // 兼容旧版本 globalData
114
- appOptions.globalData = vm.$options.globalData || {}
115
- // 将 methods 中的方法挂在 getApp()
116
- const methods = vm.$options.methods
117
- if (methods) {
118
- Object.keys(methods).forEach(name => {
119
- appOptions[name] = methods[name]
120
- })
121
- }
122
-
123
- initHooks(appOptions, hooks)
124
-
125
- return appOptions
126
- }
1
+ import Vue from 'vue'
2
+
3
+ import {
4
+ initHooks,
5
+ initMocks
6
+ } from 'uni-wrapper/util'
7
+
8
+ import {
9
+ initAppLocale
10
+ } from 'uni-helpers/i18n/index'
11
+
12
+ import EventChannel from 'uni-helpers/EventChannel'
13
+
14
+ import {
15
+ getEventChannel
16
+ } from 'uni-helpers/navigate-to'
17
+
18
+ import {
19
+ uniIdMixin
20
+ } from 'uni-shared'
21
+
22
+ const hooks = [
23
+ 'onShow',
24
+ 'onHide',
25
+ 'onError',
26
+ 'onPageNotFound',
27
+ 'onThemeChange',
28
+ 'onUnhandledRejection'
29
+ ]
30
+
31
+ if (__PLATFORM__ === 'mp-alipay') {
32
+ hooks.push('onShareAppMessage')
33
+ }
34
+
35
+ function initEventChannel () {
36
+ Vue.prototype.getOpenerEventChannel = function () {
37
+ // 微信小程序使用自身getOpenerEventChannel
38
+ if (__PLATFORM__ === 'mp-weixin') {
39
+ return this.$scope.getOpenerEventChannel()
40
+ }
41
+ if (!this.__eventChannel__) {
42
+ this.__eventChannel__ = new EventChannel()
43
+ }
44
+ return this.__eventChannel__
45
+ }
46
+ const callHook = Vue.prototype.__call_hook
47
+ Vue.prototype.__call_hook = function (hook, args) {
48
+ if (hook === 'onLoad' && args && args.__id__) {
49
+ this.__eventChannel__ = getEventChannel(args.__id__)
50
+ delete args.__id__
51
+ }
52
+ return callHook.call(this, hook, args)
53
+ }
54
+ }
55
+
56
+ function initScopedSlotsParams () {
57
+ const center = {}
58
+ const parents = {}
59
+
60
+ Vue.prototype.$hasScopedSlotsParams = function (vueId) {
61
+ const has = center[vueId]
62
+ if (!has) {
63
+ parents[vueId] = this
64
+ this.$on('hook:destroyed', () => {
65
+ delete parents[vueId]
66
+ })
67
+ }
68
+ return has
69
+ }
70
+
71
+ Vue.prototype.$getScopedSlotsParams = function (vueId, name, key) {
72
+ const data = center[vueId]
73
+ if (data) {
74
+ const object = data[name] || {}
75
+ return key ? object[key] : object
76
+ } else {
77
+ parents[vueId] = this
78
+ this.$on('hook:destroyed', () => {
79
+ delete parents[vueId]
80
+ })
81
+ }
82
+ }
83
+
84
+ Vue.prototype.$setScopedSlotsParams = function (name, value) {
85
+ const vueIds = this.$options.propsData.vueId
86
+ if (vueIds) {
87
+ const vueId = vueIds.split(',')[0]
88
+ const object = center[vueId] = center[vueId] || {}
89
+ object[name] = value
90
+ if (parents[vueId]) {
91
+ parents[vueId].$forceUpdate()
92
+ }
93
+ }
94
+ }
95
+
96
+ Vue.mixin({
97
+ destroyed () {
98
+ const propsData = this.$options.propsData
99
+ const vueId = propsData && propsData.vueId
100
+ if (vueId) {
101
+ delete center[vueId]
102
+ delete parents[vueId]
103
+ }
104
+ }
105
+ })
106
+ }
107
+
108
+ export default function parseBaseApp (vm, {
109
+ mocks,
110
+ initRefs
111
+ }) {
112
+ initEventChannel()
113
+ if (__PLATFORM__ === 'mp-weixin' || __PLATFORM__ === 'mp-qq' || __PLATFORM__ === 'mp-toutiao' || __PLATFORM__ ===
114
+ 'mp-kuaishou' || __PLATFORM__ === 'mp-alipay' || __PLATFORM__ === 'mp-baidu' || __PLATFORM__ === 'mp-lark') {
115
+ initScopedSlotsParams()
116
+ }
117
+ if (vm.$options.store) {
118
+ Vue.prototype.$store = vm.$options.store
119
+ }
120
+ uniIdMixin(Vue)
121
+
122
+ Vue.prototype.mpHost = __PLATFORM__
123
+
124
+ Vue.mixin({
125
+ beforeCreate () {
126
+ if (!this.$options.mpType) {
127
+ return
128
+ }
129
+
130
+ this.mpType = this.$options.mpType
131
+
132
+ this.$mp = {
133
+ data: {},
134
+ [this.mpType]: this.$options.mpInstance
135
+ }
136
+
137
+ this.$scope = this.$options.mpInstance
138
+
139
+ delete this.$options.mpType
140
+ delete this.$options.mpInstance
141
+ if (this.mpType === 'page' && typeof getApp === 'function') { // hack vue-i18n
142
+ const app = getApp()
143
+ if (app.$vm && app.$vm.$i18n) {
144
+ this._i18n = app.$vm.$i18n
145
+ }
146
+ }
147
+ if (this.mpType !== 'app') {
148
+ initRefs(this)
149
+ initMocks(this, mocks)
150
+ }
151
+ }
152
+ })
153
+
154
+ const appOptions = {
155
+ onLaunch (args) {
156
+ if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
157
+ return
158
+ }
159
+ if (__PLATFORM__ === 'mp-weixin' || __PLATFORM__ === 'mp-qq') {
160
+ if (wx.canIUse && !wx.canIUse('nextTick')) { // 事实 上2.2.3 即可,简单使用 2.3.0 的 nextTick 判断
161
+ console.error('当前微信基础库版本过低,请将 微信开发者工具-详情-项目设置-调试基础库版本 更换为`2.3.0`以上')
162
+ }
163
+ }
164
+
165
+ this.$vm = vm
166
+
167
+ this.$vm.$mp = {
168
+ app: this
169
+ }
170
+
171
+ this.$vm.$scope = this
172
+ // vm 上也挂载 globalData
173
+ this.$vm.globalData = this.globalData
174
+
175
+ this.$vm._isMounted = true
176
+ this.$vm.__call_hook('mounted', args)
177
+
178
+ this.$vm.__call_hook('onLaunch', args)
179
+ }
180
+ }
181
+
182
+ // 兼容旧版本 globalData
183
+ appOptions.globalData = vm.$options.globalData || {}
184
+ // 将 methods 中的方法挂在 getApp() 中
185
+ const methods = vm.$options.methods
186
+ if (methods) {
187
+ Object.keys(methods).forEach(name => {
188
+ appOptions[name] = methods[name]
189
+ })
190
+ }
191
+
192
+ initAppLocale(Vue, vm, __GLOBAL__.getSystemInfoSync().language || 'zh-Hans')
193
+
194
+ initHooks(appOptions, hooks)
195
+
196
+ return appOptions
197
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 用于延迟调用 setData
3
+ * 在 setData 真实调用的时机需执行 fixSetDataEnd
4
+ * @param {*} mpInstance
5
+ */
6
+ export function fixSetDataStart (mpInstance) {
7
+ const setData = mpInstance.setData
8
+ const setDataArgs = []
9
+ mpInstance.setData = function () {
10
+ setDataArgs.push(arguments)
11
+ }
12
+ mpInstance.__fixInitData = function () {
13
+ this.setData = setData
14
+ const fn = () => {
15
+ setDataArgs.forEach(args => {
16
+ setData.apply(this, args)
17
+ })
18
+ }
19
+ if (setDataArgs.length) {
20
+ if (this.groupSetData) {
21
+ this.groupSetData(fn)
22
+ } else {
23
+ fn()
24
+ }
25
+ }
26
+ }
27
+ }
28
+ /**
29
+ * 恢复真实的 setData 方法
30
+ * @param {*} mpInstance
31
+ */
32
+ export function fixSetDataEnd (mpInstance) {
33
+ if (mpInstance.__fixInitData) {
34
+ mpInstance.__fixInitData()
35
+ delete mpInstance.__fixInitData
36
+ }
37
+ }
@@ -0,0 +1,77 @@
1
+ let realAtob
2
+
3
+ const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
4
+ const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/
5
+
6
+ if (typeof atob !== 'function') {
7
+ realAtob = function (str) {
8
+ str = String(str).replace(/[\t\n\f\r ]+/g, '')
9
+ if (!b64re.test(str)) { throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.") }
10
+
11
+ // Adding the padding if missing, for semplicity
12
+ str += '=='.slice(2 - (str.length & 3))
13
+ var bitmap; var result = ''; var r1; var r2; var i = 0
14
+ for (; i < str.length;) {
15
+ bitmap = b64.indexOf(str.charAt(i++)) << 18 | b64.indexOf(str.charAt(i++)) << 12 |
16
+ (r1 = b64.indexOf(str.charAt(i++))) << 6 | (r2 = b64.indexOf(str.charAt(i++)))
17
+
18
+ result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255)
19
+ : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255)
20
+ : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255)
21
+ }
22
+ return result
23
+ }
24
+ } else {
25
+ // 注意atob只能在全局对象上调用,例如:`const Base64 = {atob};Base64.atob('xxxx')`是错误的用法
26
+ realAtob = atob
27
+ }
28
+
29
+ function b64DecodeUnicode (str) {
30
+ return decodeURIComponent(realAtob(str).split('').map(function (c) {
31
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
32
+ }).join(''))
33
+ }
34
+
35
+ function getCurrentUserInfo () {
36
+ const token = (__PLATFORM__ === 'h5' || __PLATFORM__ === 'app-plus' ? uni : __GLOBAL__).getStorageSync('uni_id_token') || ''
37
+ const tokenArr = token.split('.')
38
+ if (!token || tokenArr.length !== 3) {
39
+ return {
40
+ uid: null,
41
+ role: [],
42
+ permission: [],
43
+ tokenExpired: 0
44
+ }
45
+ }
46
+ let userInfo
47
+ try {
48
+ userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1]))
49
+ } catch (error) {
50
+ throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message)
51
+ }
52
+ userInfo.tokenExpired = userInfo.exp * 1000
53
+ delete userInfo.exp
54
+ delete userInfo.iat
55
+ return userInfo
56
+ }
57
+
58
+ export function uniIdMixin (Vue) {
59
+ Vue.prototype.uniIDHasRole = function (roleId) {
60
+ const {
61
+ role
62
+ } = getCurrentUserInfo()
63
+ return role.indexOf(roleId) > -1
64
+ }
65
+ Vue.prototype.uniIDHasPermission = function (permissionId) {
66
+ const {
67
+ permission
68
+ } = getCurrentUserInfo()
69
+ return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1
70
+ }
71
+ Vue.prototype.uniIDTokenValid = function () {
72
+ const {
73
+ tokenExpired
74
+ } = getCurrentUserInfo()
75
+ return tokenExpired > Date.now()
76
+ }
77
+ }
@@ -193,3 +193,5 @@ export function deepClone (vnodes, createElement) {
193
193
 
194
194
  return vnodes.map(cloneVNode)
195
195
  }
196
+
197
+ export * from './uni-id-mixin'