@dcloudio/uni-cli-shared 2.0.1-35320220729002 → 2.0.1-36220220914001

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,137 +1,154 @@
1
1
  <template>
2
2
  <view @click="onclick">
3
- <slot
4
- :options="options"
5
- :data="adData"
6
- />
3
+ <slot :options="options" :data="adData" :loading="loading" :error="errorMessage" />
7
4
  </view>
8
5
  </template>
9
6
 
10
7
  <script>
11
- const AD_URL = 'https://wxac1.dcloud.net.cn/tuiaApplet/acs'
12
- const AD_REPORT_URL = 'https://wxac1.dcloud.net.cn/tuiaApplet/acs'
13
- const WEBVIEW_PATH = '/uni_modules/uni-ad-interactive/pages/uni-ad-interactive/uni-ad-interactive'
8
+ const AD_URL = 'https://wxac1.dcloud.net.cn/openPage/acs'
9
+ const AD_REPORT_URL = 'https://wxac1.dcloud.net.cn/openPage/acs'
10
+ //const WEBVIEW_PATH = '/uni_modules/uni-ad-interactive/pages/uni-ad-interactive/uni-ad-interactive'
14
11
 
15
- const events = {
16
- load: 'load',
17
- close: 'close',
18
- error: 'error'
19
- }
12
+ const events = {
13
+ load: 'load',
14
+ close: 'close',
15
+ error: 'error'
16
+ }
20
17
 
21
- const OpenTypes = {
22
- Interactive: 'interactive'
23
- }
18
+ const OpenTypes = {
19
+ Interactive: 'interactive'
20
+ }
24
21
 
25
- export default {
26
- name: 'AdInteractive',
27
- props: {
28
- options: {
29
- type: [Object, Array],
30
- default () {
31
- return {}
22
+ export default {
23
+ name: 'AdInteractive',
24
+ props: {
25
+ options: {
26
+ type: [Object, Array],
27
+ default () {
28
+ return {}
29
+ }
30
+ },
31
+ disabled: {
32
+ type: [Boolean, String],
33
+ default: false
34
+ },
35
+ adpid: {
36
+ type: [Number, String],
37
+ default: ''
38
+ },
39
+ openType: {
40
+ type: String,
41
+ default: 'interactive'
42
+ },
43
+ openPagePath: {
44
+ type: String,
45
+ default: ""
32
46
  }
33
47
  },
34
- adpid: {
35
- type: [Number, String],
36
- default: ''
37
- },
38
- openUrl: {
39
- type: String,
40
- default: WEBVIEW_PATH
41
- }
42
- },
43
- data () {
44
- return {
45
- adData: {}
46
- }
47
- },
48
- created () {
49
- this._uniAdPlugin = null
50
- this._interactiveUrl = null
51
- if (this.openType === OpenTypes.Interactive) {
52
- this.getAdData()
53
- }
54
- },
55
- methods: {
56
- show () {
57
- if (this._uniAdPlugin === null) {
58
- this._uniAdPlugin = this.selectComponent('.uni-ad-plugin')
48
+ data() {
49
+ return {
50
+ adData: null,
51
+ loading: false,
52
+ errorMessage: ""
59
53
  }
60
- this._uniAdPlugin.show()
61
54
  },
62
- getAdData () {
63
- if (!this.adpid) {
64
- this.$emit(events.error, {
65
- code: -5002,
66
- message: 'invalid adpid'
67
- })
68
- return
55
+ created() {
56
+ this._uniAdPlugin = null
57
+ this._interactiveUrl = null
58
+ if (this.openPagePath) {
59
+ this.getAdData()
69
60
  }
61
+ },
62
+ methods: {
63
+ show() {
64
+ if (this._uniAdPlugin === null) {
65
+ this._uniAdPlugin = this.selectComponent('.uni-ad-plugin')
66
+ }
67
+ this._uniAdPlugin.show()
68
+ },
69
+ getAdData() {
70
+ if (!this.adpid) {
71
+ this.$emit(events.error, {
72
+ code: -5002,
73
+ message: 'invalid adpid'
74
+ })
75
+ return
76
+ }
70
77
 
71
- uni.request({
72
- url: AD_URL,
73
- method: 'POST',
74
- data: {
75
- adpid: this.adpid
76
- },
77
- timeout: 5000,
78
- dataType: 'json',
79
- success: (res) => {
80
- console.log(res.data)
78
+ this.loading = true
81
79
 
82
- if (res.statusCode !== 200) {
83
- this.$emit(events.error, {
84
- code: res.statusCode,
85
- message: res.statusCode
86
- })
87
- return
88
- }
80
+ uni.request({
81
+ url: AD_URL,
82
+ method: 'POST',
83
+ data: {
84
+ adpid: this.adpid
85
+ },
86
+ timeout: 5000,
87
+ dataType: 'json',
88
+ success: (res) => {
89
+ if (res.statusCode !== 200) {
90
+ this.$emit(events.error, {
91
+ errCode: res.statusCode,
92
+ errMsg: res.statusCode
93
+ })
94
+ return
95
+ }
89
96
 
90
- const responseData = res.data
91
- if (responseData.ret === 0) {
92
- this._interactiveUrl = responseData.data.adp_url
93
- this.adData.imgUrl = responseData.data.icon_url
94
- this.adData.openUrl = this.openUrl + '?url=' + encodeURIComponent(this._interactiveUrl)
95
- this.$emit(events.load, {})
96
- } else {
97
+ const responseData = res.data
98
+ if (responseData.ret === 0) {
99
+ this._interactiveUrl = responseData.data.adp_url
100
+ this.adData = {
101
+ imgUrl: responseData.data.icon_url,
102
+ openPath: this.openPagePath + '?url=' + encodeURIComponent(this._interactiveUrl)
103
+ }
104
+ this.$emit(events.load, this.adData)
105
+ } else {
106
+ const errMsg = {
107
+ errCode: responseData.ret,
108
+ errMsg: responseData.msg
109
+ }
110
+ this.errorMessage = errMsg
111
+ this.$emit(events.error, errMsg)
112
+ }
113
+ },
114
+ fail: (err) => {
97
115
  this.$emit(events.error, {
98
- code: responseData.ret,
99
- message: responseData.msg
116
+ errCode: '',
117
+ errMsg: err.errMsg
100
118
  })
119
+ },
120
+ complete: () => {
121
+ this.loading = false
101
122
  }
102
- },
103
- fail: (err) => {
104
- this.$emit(events.error, {
105
- code: '',
106
- message: err.errMsg
107
- })
123
+ })
124
+ },
125
+ onclick() {
126
+ if (this.disabled) {
127
+ return
128
+ }
129
+ if (!this._interactiveUrl) {
130
+ return
108
131
  }
109
- })
110
- },
111
- onclick () {
112
- if (this.openType !== OpenTypes.Interactive || !this._interactiveUrl) {
113
- return
114
- }
115
132
 
116
- uni.navigateTo({
117
- url: this.adData.openUrl
118
- })
133
+ uni.navigateTo({
134
+ url: this.adData.openPath
135
+ })
119
136
 
120
- this._report()
121
- },
122
- _report () {
123
- uni.request({
124
- url: AD_REPORT_URL,
125
- data: {
126
- adpid: this.adpid,
127
- t: '10019'
128
- },
129
- timeout: 5000,
130
- dataType: 'json'
131
- })
137
+ this._report()
138
+ },
139
+ _report() {
140
+ uni.request({
141
+ url: AD_REPORT_URL,
142
+ data: {
143
+ adpid: this.adpid,
144
+ t: '10019'
145
+ },
146
+ timeout: 5000,
147
+ dataType: 'json'
148
+ })
149
+ }
132
150
  }
133
151
  }
134
- }
135
152
  </script>
136
153
 
137
154
  <style>
@@ -27,6 +27,12 @@ export default {
27
27
  loadnext: {
28
28
  type: [Boolean, String],
29
29
  default: false
30
+ },
31
+ urlCallback: {
32
+ type: Object,
33
+ default () {
34
+ return {}
35
+ }
30
36
  }
31
37
  },
32
38
  data () {
@@ -58,7 +64,31 @@ export default {
58
64
  show () {
59
65
  this.errorMessage = null
60
66
  this._ad = this.selectComponent('.uniad-plugin')
61
- this._ad.show()
67
+ if (this._hasCallback()) {
68
+ const userCryptoManager = wx.getUserCryptoManager()
69
+ userCryptoManager.getLatestUserKey({
70
+ success: ({
71
+ encryptKey,
72
+ iv,
73
+ version,
74
+ expireTime
75
+ }) => {
76
+ this._ad.show({
77
+ userId: this.urlCallback.userId || '',
78
+ extra: this.urlCallback.extra || '',
79
+ encryptKey,
80
+ iv,
81
+ version,
82
+ expireTime
83
+ })
84
+ },
85
+ fail: (err) => {
86
+ this._dispatchEvent(EventType.Error, err)
87
+ }
88
+ })
89
+ } else {
90
+ this._ad.show()
91
+ }
62
92
  },
63
93
 
64
94
  _onclick () {
@@ -80,6 +110,11 @@ export default {
80
110
  return result
81
111
  },
82
112
 
113
+ _hasCallback () {
114
+ return false
115
+ // return (typeof this.urlCallback === 'object' && Object.keys(this.urlCallback).length > 0)
116
+ },
117
+
83
118
  _onmpload (e) {
84
119
  this.loading = false
85
120
  this._dispatchEvent(EventType.Load, {})
@@ -87,6 +122,31 @@ export default {
87
122
 
88
123
  _onmpclose (e) {
89
124
  this._dispatchEvent(EventType.Close, e.detail)
125
+ if (e.detail.adsdata) {
126
+ const adv = e.detail.adv
127
+ const adsdata = e.detail.adsdata
128
+ const version = e.detail.version
129
+
130
+ /* eslint-disable no-undef */
131
+ uniCloud.callFunction({
132
+ name: 'uniAdCallback',
133
+ data: {
134
+ adv: adv,
135
+ adsdata: adsdata,
136
+ version: version
137
+ },
138
+ secretType: 'both',
139
+ success: (res) => {
140
+ },
141
+ fail: (err) => {
142
+ this._dispatchEvent(EventType.Error, err)
143
+ }
144
+ })
145
+
146
+ delete e.detail.adv
147
+ delete e.detail.adsdata
148
+ delete e.detail.version
149
+ }
90
150
  },
91
151
 
92
152
  _onmperror (e) {
package/lib/preprocess.js CHANGED
@@ -5,7 +5,10 @@ const DEFAULT_KEYS = [
5
5
  'APP',
6
6
  'APP-PLUS-NVUE',
7
7
  'APP-VUE',
8
- 'APP-NVUE'
8
+ 'APP-NVUE',
9
+ 'APP-ANDROID',
10
+ 'APP-IOS',
11
+ 'WEB'
9
12
  ]
10
13
 
11
14
  function normalize (name) {
@@ -44,14 +47,26 @@ module.exports = function initPreprocess (name, platforms, userDefines = {}) {
44
47
  nvueContext.APP_PLUS = true
45
48
  nvueContext.APP_NVUE = true
46
49
  nvueContext.APP_PLUS_NVUE = true
47
- }
48
50
 
51
+ if (process.env.UNI_APP_PLATFORM === 'android') {
52
+ defaultContext.APP_ANDROID = true
53
+ } else if (process.env.UNI_APP_PLATFORM === 'ios') {
54
+ defaultContext.APP_IOS = true
55
+ } else {
56
+ defaultContext.APP_ANDROID = true
57
+ defaultContext.APP_IOS = true
58
+ }
59
+ }
60
+ if (name === 'h5') {
61
+ defaultContext.WEB = true
62
+ }
49
63
  if (name.startsWith('mp-')) {
50
64
  vueContext.MP = true
51
65
  }
52
66
 
53
67
  if (name.startsWith('app-')) {
54
68
  vueContext.APP = true
69
+ nvueContext.APP = true
55
70
  }
56
71
 
57
72
  if (name === 'quickapp-webview') {
package/lib/source-map.js CHANGED
@@ -4,16 +4,10 @@ const webpack = require('webpack')
4
4
 
5
5
  const {
6
6
  normalizePath,
7
+ pathToRegexp,
7
8
  isInHBuilderX
8
9
  } = require('@dcloudio/uni-cli-shared/lib/util')
9
10
 
10
- const isWin = /^win/.test(process.platform)
11
-
12
- function genTranspileDepRegex (depPath) {
13
- return new RegExp(isWin
14
- ? depPath.replace(/\\/g, '\\\\') // double escape for windows style path
15
- : depPath)
16
- }
17
11
  let sourceRoot = false
18
12
 
19
13
  function getSourceRoot () {
@@ -60,7 +54,7 @@ module.exports = {
60
54
  },
61
55
  createEvalSourceMapDevToolPlugin () {
62
56
  return new webpack.EvalSourceMapDevToolPlugin({
63
- test: genTranspileDepRegex(process.env.UNI_INPUT_DIR),
57
+ test: pathToRegexp(process.env.UNI_INPUT_DIR, { start: true }),
64
58
  exclude,
65
59
  moduleFilenameTemplate
66
60
  })
package/lib/util.js CHANGED
@@ -2,6 +2,8 @@ const path = require('path')
2
2
  const fs = require('fs')
3
3
  const hash = require('hash-sum')
4
4
  const crypto = require('crypto')
5
+ const escapeStringRegexp = require('escape-string-regexp')
6
+ const escapeGlob = require('glob-escape')
5
7
 
6
8
  const isWin = /^win/.test(process.platform)
7
9
 
@@ -121,6 +123,34 @@ function normalizeNodeModules (str) {
121
123
 
122
124
  const _hasOwnProperty = Object.prototype.hasOwnProperty
123
125
 
126
+ /**
127
+ * pathToRegexp
128
+ * @param {string} pathString
129
+ * @param {{start:?boolean,end:?boolean,global:?boolean}?} options
130
+ * @returns {RegExp}
131
+ */
132
+ function pathToRegexp (pathString, options = {}) {
133
+ return new RegExp((options.start ? '^' : '') + escapeStringRegexp(pathString) + (options.end ? '$' : ''), 'i' + (options.global ? 'g' : ''))
134
+ }
135
+
136
+ /**
137
+ * pathToGlob
138
+ * @param {string} pathString
139
+ * @param {string} glob
140
+ * @param {{windows:?boolean,escape:?boolean}?} options
141
+ * @returns {string}
142
+ */
143
+ function pathToGlob (pathString, glob, options = {}) {
144
+ const isWindows = 'windows' in options ? options.windows : /^win/.test(process.platform)
145
+ const useEscape = options.escape
146
+ const str = isWindows ? pathString.replace(/\\/g, '/') : pathString
147
+ let safeStr = escapeGlob(str)
148
+ if (isWindows || !useEscape) {
149
+ safeStr = safeStr.replace(/\\(.)/g, '[$1]')
150
+ }
151
+ return path.posix.join(safeStr, glob)
152
+ }
153
+
124
154
  module.exports = {
125
155
  isInHBuilderX,
126
156
  isInHBuilderXAlpha,
@@ -149,6 +179,8 @@ module.exports = {
149
179
  hyphenate,
150
180
  normalizePath,
151
181
  convertStaticStyle,
182
+ pathToRegexp,
183
+ pathToGlob,
152
184
  getComponentName: cached((str) => {
153
185
  if (str.indexOf('wx-') === 0) {
154
186
  return str.replace('wx-', 'weixin-')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.1-35320220729002",
3
+ "version": "2.0.1-36220220914001",
4
4
  "description": "uni-cli-shared",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -19,9 +19,11 @@
19
19
  "author": "fxy060608",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
+ "escape-string-regexp": "^4.0.0",
23
+ "glob-escape": "^0.0.2",
22
24
  "hash-sum": "^1.0.2",
23
25
  "postcss-urlrewrite": "^0.2.2",
24
26
  "strip-json-comments": "^2.0.1"
25
27
  },
26
- "gitHead": "99c489d7a19425ade612162abd21b441260e7ba7"
28
+ "gitHead": "67fdc447148dd3e05d528bfb4e5ed103430ec05b"
27
29
  }