vue2-client 1.8.11 → 1.8.13

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.
@@ -1,257 +1,243 @@
1
- <template><div ref="domRef">Loading...</div></template>
2
-
3
- <script>
4
- // import "amis/sdk/sdk.js";
5
- // import "amis/sdk/sdk.css";
6
- // import "amis/sdk/iconfont.css";
7
-
8
- // 可以不引用, 如果你不想要任何辅助类样式的话 (比如 `m-t-xs` 这种)
9
- // https://aisuda.bce.baidu.com/amis/zh-CN/style/index
10
- // import 'amis/sdk/helper.css'
11
- import qs from 'qs'
12
- import Vue from 'vue'
13
- import Index from '@vue2-client/base-client/components/index.js'
14
- let React
15
- let amisLib
16
- let scoped
17
- const apps = {}
18
- function loadScript (src, callback) {
19
- const script = document.createElement('script')
20
- script.setAttribute('type', 'text/javascript')
21
- script.setAttribute('src', src)
22
- script.onload = () => callback()
23
- script.onerror = () => callback(new Error(`Failed to load ${src}`))
24
- document.body.appendChild(script)
25
- }
26
- const vueList = {}
27
-
28
- // eslint-disable-next-line no-unused-vars
29
- function CustomComponent (props, dom) {
30
- const store = Vue.$store
31
- const router = Vue.$router
32
- const i18n = Vue.$i18n
33
- console.log('props', props)
34
- React.useEffect(function () {
35
- vueList[props.$schema.name] = new Vue({
36
- router,
37
- store,
38
- i18n,
39
- render: h => h(Index[props.$schema.type], {
40
- props: props.$schema
41
- })
42
- }).$mount(dom.current)
43
- }, [])
44
- const app = React.createElement('div', {
45
- ref: dom
46
- })
47
- if (apps[props.name] !== undefined) {
48
- const vue = vueList[props.$schema.name]
49
- vue.$children[0].active(props.data)
50
- } else {
51
- apps[props.name] = app
52
- }
53
- return app
54
- }
55
-
56
- function loadStyles (styles) {
57
- for (const path of styles) {
58
- const style = document.createElement('link')
59
- style.setAttribute('rel', 'stylesheet')
60
- style.setAttribute('type', 'text/css')
61
- style.setAttribute('href', path)
62
- document.head.appendChild(style)
63
- }
64
- }
65
- // eslint-disable-next-line no-unused-vars
66
- function appstyle (data) {
67
- console.log('111111111111')
68
- }
69
- // 动态导入组件
70
-
71
- function loadSDK () {
72
- return new Promise((resolve, reject) => {
73
- if (window.amisRequire) {
74
- resolve()
75
- return
76
- }
77
- loadStyles([
78
- '/amis/sdk/sdk.css',
79
- '/amis/sdk/helper.css',
80
- '/amis/sdk/iconfont.css',
81
- ])
82
- loadScript('/amis/sdk/sdk.js', (err) => {
83
- if (err) {
84
- reject(err)
85
- return
86
- }
87
- resolve()
88
- })
89
- })
90
- }
91
-
92
- export default {
93
- name: 'AMISRenderer',
94
- components: {},
95
- props: {
96
- schema: {
97
- type: Object,
98
- default: {
99
- type: 'page',
100
- body: 'Hello World!',
101
- },
102
- },
103
- locals: {
104
- type: Object,
105
- default: () => ({}),
106
- },
107
- props: {
108
- type: Object,
109
- default: () => ({}),
110
- },
111
- env: {
112
- type: Object,
113
- default: () => ({}),
114
- },
115
- },
116
- data () {
117
- const router = this.$router
118
- return {
119
- // 这里面的数据所有 amis 页面都可以获取到
120
- // 可以用来放一下公共数据,比如用户信息等
121
- // 不要放受控数据,受控数据应该通过 data 下发
122
- context: {
123
- siteName: 'AMIS DEMO',
124
- },
125
- get location () {
126
- const current = router.history.current
127
- return {
128
- pathname: current.path,
129
- hash: current.hash,
130
- query: current.query,
131
- search: `?${qs.stringify(current.query)}`,
132
- }
133
- },
134
- loading: false,
135
- amisInstance: null,
136
- unmounted: false,
137
- applist: {}
138
- }
139
- },
140
-
141
- watch: {
142
- locals: function () {
143
- this.updateProps()
144
- },
145
- props: function () {
146
- this.updateProps()
147
- },
148
- $route: function () {
149
- this.updateProps()
150
- },
151
- },
152
- async mounted () {
153
- try {
154
- this.loading = true
155
- await loadSDK()
156
- } finally {
157
- this.loading = false
158
- }
159
- if (this.unmounted) {
160
- return
161
- }
162
- React = window.amisRequire('react')
163
- amisLib = window.amisRequire('amis')
164
- scoped = window.amisRequire('amis/embed')
165
- const { normalizeLink } = amisLib
166
- const router = this.$router
167
- // eslint-disable-next-line no-prototype-builtins
168
- // console.log('this.schema.type', this.schema.type)
169
-
170
- amisLib.Renderer({
171
- test: new RegExp(`(^|\/)${this.schema.type}`)
172
- })(props => CustomComponent(props, this.$el))
173
-
174
- const instance = scoped.embed(
175
- this.$el,
176
- this.schema,
177
- {
178
- data: {
179
- ...this.locals,
180
- },
181
- context: this.context,
182
- location: this.location,
183
-
184
- // todo 下发 location 对象
185
- ...this.props,
186
- },
187
- {
188
- // 覆盖 amis env
189
- // 参考 https://aisuda.bce.baidu.com/amis/zh-CN/docs/start/getting-started#sdk
190
- jumpTo: (to, action) => {
191
- if (to === 'goBack') {
192
- return router.go(-1)
193
- }
194
-
195
- to = normalizeLink(to, this.location)
196
-
197
- if (action?.actionType === 'url') {
198
- action.blank === false ? router.push(to) : window.open(to)
199
- return
200
- }
201
-
202
- // 主要是支持 nav 中的跳转
203
- if (action && to && action.target) {
204
- window.open(to, action.target)
205
- return
206
- }
207
-
208
- if (/^https?:\/\//.test(to)) {
209
- window.location.replace(to)
210
- } else {
211
- router.push(to)
212
- }
213
- },
214
-
215
- updateLocation: (location, replace) => {
216
- if (location === 'goBack') {
217
- return router.go(-1)
218
- }
219
-
220
- location = normalizeLink(location, this.location)
221
- replace ? router.replace(location) : router.replace(location)
222
- },
223
-
224
- ...this.env,
225
- },
226
- () => {
227
- this.$emit('ready', {
228
- instance,
229
- })
230
- }
231
- )
232
- this.amisInstance = instance
233
- },
234
-
235
- methods: {
236
- updateProps () {
237
- // eslint-disable-next-line no-unused-expressions
238
- this.amisInstance?.updateProps({
239
- data: {
240
- ...this.locals,
241
- },
242
- context: this.context,
243
- ...this.props,
244
- })
245
- },
246
- initConfig () {
247
- console.warn('initConfig')
248
- }
249
- },
250
-
251
- destroyed () {
252
- this.unmounted = true
253
- // eslint-disable-next-line no-unused-expressions
254
- this.amisInstance?.unmount()
255
- },
256
- }
257
- </script>
1
+ <template><div>Loading...</div></template>
2
+
3
+ <script>
4
+ // import "amis/sdk/sdk.js";
5
+ // import "amis/sdk/sdk.css";
6
+ // import "amis/sdk/iconfont.css";
7
+
8
+ // 可以不引用, 如果你不想要任何辅助类样式的话 (比如 `m-t-xs` 这种)
9
+ // https://aisuda.bce.baidu.com/amis/zh-CN/style/index
10
+ // import 'amis/sdk/helper.css'
11
+ import qs from 'qs'
12
+ import Vue from 'vue'
13
+ import Index from '@vue2-client/base-client/components/index.js'
14
+ import locale from 'ant-design-vue/es/locale-provider/zh_CN'
15
+
16
+ function loadScript (src, callback) {
17
+ const script = document.createElement('script')
18
+ script.setAttribute('type', 'text/javascript')
19
+ script.setAttribute('src', src)
20
+ script.onload = () => callback()
21
+ script.onerror = () => callback(new Error(`Failed to load ${src}`))
22
+ document.body.appendChild(script)
23
+ }
24
+
25
+ function loadStyles (styles) {
26
+ for (const path of styles) {
27
+ const style = document.createElement('link')
28
+ style.setAttribute('rel', 'stylesheet')
29
+ style.setAttribute('type', 'text/css')
30
+ style.setAttribute('href', path)
31
+ document.head.appendChild(style)
32
+ }
33
+ }
34
+
35
+ // 动态导入组件
36
+ function CustomComponent (props) {
37
+ const React = window.amisRequire('react')
38
+ const dom = React.useRef(null)
39
+ const store = Vue.$store
40
+ const router = Vue.$router
41
+ const i18n = Vue.$i18n
42
+ React.useEffect(function () {
43
+ new Vue({
44
+ router,
45
+ store,
46
+ i18n,
47
+ render: h => h('a-config-provider', {
48
+ props: {
49
+ locale: locale,
50
+ popContainer: document.getElementById('popContainer')
51
+ }
52
+ }, [
53
+ h(Index[props.$schema.type], {
54
+ props: props.$schema
55
+ })
56
+ ])
57
+ }).$mount(dom.current)
58
+ })
59
+ return React.createElement('div', {
60
+ ref: dom
61
+ })
62
+ }
63
+
64
+ function loadSDK () {
65
+ return new Promise((resolve, reject) => {
66
+ if (window.amisRequire) {
67
+ resolve()
68
+ return
69
+ }
70
+ loadStyles([
71
+ '/amis/sdk/sdk.css',
72
+ '/amis/sdk/helper.css',
73
+ '/amis/sdk/iconfont.css',
74
+ ])
75
+ loadScript('/amis/sdk/sdk.js', (err) => {
76
+ if (err) {
77
+ reject(err)
78
+ return
79
+ }
80
+ resolve()
81
+ })
82
+ })
83
+ }
84
+
85
+ export default {
86
+ name: 'AMISRenderer',
87
+ components: {},
88
+ props: {
89
+ schema: {
90
+ type: Object,
91
+ default: {
92
+ type: 'page',
93
+ body: 'Hello World!',
94
+ },
95
+ },
96
+ locals: {
97
+ type: Object,
98
+ default: () => ({}),
99
+ },
100
+ props: {
101
+ type: Object,
102
+ default: () => ({}),
103
+ },
104
+ env: {
105
+ type: Object,
106
+ default: () => ({}),
107
+ },
108
+ },
109
+ data () {
110
+ const router = this.$router
111
+ return {
112
+ // 这里面的数据所有 amis 页面都可以获取到
113
+ // 可以用来放一下公共数据,比如用户信息等
114
+ // 不要放受控数据,受控数据应该通过 data 下发
115
+ context: {
116
+ siteName: 'AMIS DEMO',
117
+ },
118
+ get location () {
119
+ const current = router.history.current
120
+ return {
121
+ pathname: current.path,
122
+ hash: current.hash,
123
+ query: current.query,
124
+ search: `?${qs.stringify(current.query)}`,
125
+ }
126
+ },
127
+ loading: false,
128
+ amisInstance: null,
129
+ unmounted: false,
130
+ }
131
+ },
132
+
133
+ watch: {
134
+ locals: function () {
135
+ this.updateProps()
136
+ },
137
+ props: function () {
138
+ this.updateProps()
139
+ },
140
+ $route: function () {
141
+ this.updateProps()
142
+ },
143
+ },
144
+ async mounted () {
145
+ try {
146
+ this.loading = true
147
+ await loadSDK()
148
+ } finally {
149
+ this.loading = false
150
+ }
151
+ if (this.unmounted) {
152
+ return
153
+ }
154
+
155
+ const amisLib = window.amisRequire('amis')
156
+ const scoped = window.amisRequire('amis/embed')
157
+ const { normalizeLink } = amisLib
158
+ const router = this.$router
159
+ amisLib.Renderer({
160
+ test: new RegExp(`(^|\/)${this.schema.type}`)
161
+ })(CustomComponent)
162
+ const instance = scoped.embed(
163
+ this.$el,
164
+ this.schema,
165
+ {
166
+ data: {
167
+ ...this.locals,
168
+ },
169
+ context: this.context,
170
+ location: this.location,
171
+
172
+ // todo 下发 location 对象
173
+ ...this.props,
174
+ },
175
+ {
176
+ // 覆盖 amis env
177
+ // 参考 https://aisuda.bce.baidu.com/amis/zh-CN/docs/start/getting-started#sdk
178
+ jumpTo: (to, action) => {
179
+ if (to === 'goBack') {
180
+ return router.go(-1)
181
+ }
182
+
183
+ to = normalizeLink(to, this.location)
184
+
185
+ if (action?.actionType === 'url') {
186
+ action.blank === false ? router.push(to) : window.open(to)
187
+ return
188
+ }
189
+
190
+ // 主要是支持 nav 中的跳转
191
+ if (action && to && action.target) {
192
+ window.open(to, action.target)
193
+ return
194
+ }
195
+
196
+ if (/^https?:\/\//.test(to)) {
197
+ window.location.replace(to)
198
+ } else {
199
+ router.push(to)
200
+ }
201
+ },
202
+
203
+ updateLocation: (location, replace) => {
204
+ if (location === 'goBack') {
205
+ return router.go(-1)
206
+ }
207
+
208
+ location = normalizeLink(location, this.location)
209
+ replace ? router.replace(location) : router.replace(location)
210
+ },
211
+
212
+ ...this.env,
213
+ },
214
+ () => {
215
+ this.$emit('ready', {
216
+ instance,
217
+ })
218
+ }
219
+ )
220
+
221
+ this.amisInstance = instance
222
+ },
223
+
224
+ methods: {
225
+ updateProps () {
226
+ // eslint-disable-next-line no-unused-expressions
227
+ this.amisInstance?.updateProps({
228
+ data: {
229
+ ...this.locals,
230
+ },
231
+ context: this.context,
232
+ ...this.props,
233
+ })
234
+ },
235
+ },
236
+
237
+ destroyed () {
238
+ this.unmounted = true
239
+ // eslint-disable-next-line no-unused-expressions
240
+ this.amisInstance?.unmount()
241
+ },
242
+ }
243
+ </script>
@@ -1,3 +1,3 @@
1
- import CitySelect from './CitySelect'
2
-
3
- export default CitySelect
1
+ import CitySelect from './CitySelect'
2
+
3
+ export default CitySelect