@dcloudio/uni-cli-shared 2.0.2-alpha-3080420230602001 → 2.0.2-alpha-3080520230616001

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.
@@ -8,9 +8,12 @@
8
8
  </template>
9
9
 
10
10
  <script>
11
- // #ifndef MP-WEIXIN
11
+ // #ifdef APP
12
12
  import adMixin from "./ad.mixin.js"
13
13
  // #endif
14
+ // #ifdef H5
15
+ import adMixin from "./ad.mixin.web.js"
16
+ // #endif
14
17
  // #ifdef MP-WEIXIN
15
18
  import adMixin from "./ad.mixin.mp.js"
16
19
  // #endif
@@ -55,10 +55,6 @@ export default {
55
55
  return
56
56
  }
57
57
  this._startLoading()
58
-
59
- setTimeout(() => {
60
- this._onmpload()
61
- }, 3000)
62
58
  },
63
59
 
64
60
  show () {
@@ -0,0 +1,173 @@
1
+ const AD_SERVER_URL = 'https://hac1.dcloud.net.cn/h5/gs'
2
+
3
+ const EventType = {
4
+ Load: 'load',
5
+ Close: 'close',
6
+ Error: 'error'
7
+ }
8
+
9
+ const ProviderType = 'wm'
10
+
11
+ class Process {
12
+ static Start (cmd, args) {
13
+ return new Process().openScheme(cmd)
14
+ }
15
+
16
+ constructor () {
17
+ this._a = null
18
+ }
19
+
20
+ openScheme (url) {
21
+ if (this._a == null) {
22
+ this._a = document.createElement('a')
23
+ }
24
+ this._a.href = url
25
+ this._a.click()
26
+ }
27
+ }
28
+
29
+ export default {
30
+ props: {
31
+ options: {
32
+ type: [Object, Array],
33
+ default () {
34
+ return {}
35
+ }
36
+ },
37
+ adpid: {
38
+ type: [Number, String],
39
+ default: ''
40
+ },
41
+ preload: {
42
+ type: [Boolean, String],
43
+ default: true
44
+ },
45
+ loadnext: {
46
+ type: [Boolean, String],
47
+ default: false
48
+ },
49
+ urlCallback: {
50
+ type: Object,
51
+ default () {
52
+ return {}
53
+ }
54
+ }
55
+ },
56
+ data () {
57
+ return {
58
+ adData: null,
59
+ loading: false,
60
+ showModel: false,
61
+ errorMessage: null
62
+ }
63
+ },
64
+ created () {
65
+ this._loading = false
66
+ this.adConfigData = null
67
+ },
68
+ methods: {
69
+ load () {
70
+ setTimeout(() => {
71
+ this._onmpload()
72
+ }, 200)
73
+ },
74
+
75
+ show (options) {
76
+ if (!this._isMobile()) {
77
+ this._dispatchEvent(EventType.Error, {
78
+ errCode: -1,
79
+ errMsg: '当前设备环境无效'
80
+ })
81
+ return
82
+ }
83
+
84
+ this.errorMessage = null
85
+ if (this._loading) {
86
+ return
87
+ }
88
+ this._loading = true
89
+
90
+ this._requestScheme(options)
91
+ },
92
+
93
+ getProvider () {
94
+ return ProviderType
95
+ },
96
+
97
+ _onclick () {
98
+ if (this.disabled) {
99
+ return
100
+ }
101
+
102
+ this.show()
103
+ },
104
+
105
+ _requestScheme (options = {}) {
106
+ const urlCallback = options.urlCallback || this.urlCallback
107
+ uni.request({
108
+ url: AD_SERVER_URL,
109
+ method: 'POST',
110
+ data: {
111
+ adpid: this.adpid,
112
+ userId: urlCallback.userId,
113
+ extra: urlCallback.extra
114
+ },
115
+ timeout: 5000,
116
+ dataType: 'json',
117
+ success: (res) => {
118
+ if (res.statusCode !== 200) {
119
+ this._dispatchEvent(EventType.Error, {
120
+ errCode: res.statusCode,
121
+ errMsg: res.statusCode
122
+ })
123
+ return
124
+ }
125
+
126
+ const responseData = res.data
127
+ if (responseData.ret === 0) {
128
+ Process.Start(responseData.data.openlink)
129
+ } else {
130
+ this._dispatchEvent(EventType.Error, {
131
+ errCode: responseData.ret,
132
+ errMsg: responseData.msg
133
+ })
134
+ }
135
+ },
136
+ fail: (err) => {
137
+ this.$emit(EventType.Error, {
138
+ errCode: '',
139
+ errMsg: err.errMsg
140
+ })
141
+ },
142
+ complete: () => {
143
+ this.loading = false
144
+ }
145
+ })
146
+ },
147
+
148
+ _isMobile () {
149
+ return /android|iphone/i.test(navigator.userAgent.toLowerCase())
150
+ },
151
+
152
+ _onmpload (e) {
153
+ this.loading = false
154
+ this._dispatchEvent(EventType.Load, {})
155
+ },
156
+
157
+ _onmpclose (e) {
158
+ this._dispatchEvent(EventType.Close, e.detail)
159
+ },
160
+
161
+ _onmperror (e) {
162
+ this.loading = false
163
+ this.errorMessage = JSON.stringify(e.detail)
164
+ this._dispatchEvent(EventType.Error, e.detail)
165
+ },
166
+
167
+ _dispatchEvent (type, data) {
168
+ this.$emit(type, {
169
+ detail: data
170
+ })
171
+ }
172
+ }
173
+ }
@@ -3,29 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseInject = exports.parseInjects = exports.parseUniExtApis = void 0;
6
+ exports.parseInjects = exports.parseUniExtApis = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const merge_1 = require("merge");
10
- function parseUniExtApis(vite = true) {
9
+ function parseUniExtApis(vite = true, platform, language = 'javascript') {
11
10
  const uniModulesDir = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules');
12
11
  if (!fs_extra_1.default.existsSync(uniModulesDir)) {
13
12
  return {};
14
13
  }
15
- let platform = process.env.UNI_PLATFORM;
16
- if (platform === 'h5') {
17
- platform = 'web';
18
- }
19
- else if (platform === 'app-plus') {
20
- platform = 'app';
21
- }
22
14
  const injects = {};
23
15
  fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
24
16
  // 必须以 uni- 开头
25
17
  if (!uniModuleDir.startsWith('uni-')) {
26
18
  return;
27
19
  }
28
- const pkgPath = path_1.default.resolve(uniModulesDir, uniModuleDir, 'package.json');
20
+ const uniModuleRootDir = path_1.default.resolve(uniModulesDir, uniModuleDir);
21
+ const pkgPath = path_1.default.resolve(uniModuleRootDir, 'package.json');
29
22
  if (!fs_extra_1.default.existsSync(pkgPath)) {
30
23
  return;
31
24
  }
@@ -33,18 +26,7 @@ function parseUniExtApis(vite = true) {
33
26
  const exports = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))
34
27
  ?.uni_modules?.['uni-ext-api'];
35
28
  if (exports) {
36
- const curInjects = parseInjects(vite, platform, `@/uni_modules/${uniModuleDir}`, exports);
37
- if (platform === 'app') {
38
- Object.keys(curInjects).forEach((name) => {
39
- const options = curInjects[name];
40
- // js 平台禁用了
41
- if (Array.isArray(options) && options.length === 3) {
42
- if (options[2] && options[2].js === false) {
43
- delete curInjects[name];
44
- }
45
- }
46
- });
47
- }
29
+ const curInjects = parseInjects(vite, platform, language, `@/uni_modules/${uniModuleDir}`, uniModuleRootDir, exports);
48
30
  Object.assign(injects, curInjects);
49
31
  }
50
32
  }
@@ -74,41 +56,43 @@ exports.parseUniExtApis = parseUniExtApis;
74
56
  * @param define
75
57
  * @returns
76
58
  */
77
- function parseInjects(vite = true, platform, source, exports = {}) {
59
+ function parseInjects(vite = true, platform, language, source, uniModuleRootDir, exports = {}) {
78
60
  let rootDefines = {};
79
61
  Object.keys(exports).forEach((name) => {
80
62
  if (name.startsWith('uni')) {
81
63
  rootDefines[name] = exports[name];
82
64
  }
83
65
  });
84
- const platformDefines = exports[platform];
85
- // 该平台不支持
86
- if (platformDefines === false) {
87
- return {};
88
- }
89
- if (platformDefines) {
90
- rootDefines = (0, merge_1.recursive)(true, rootDefines, platformDefines);
91
- }
92
66
  const injects = {};
93
- for (const key in rootDefines) {
94
- Object.assign(injects, parseInject(vite, platform, source, 'uni', rootDefines[key]));
67
+ if (Object.keys(rootDefines).length) {
68
+ const hasPlatformFile = uniModuleRootDir
69
+ ? fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'index.uts')) ||
70
+ fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', platform))
71
+ : true;
72
+ for (const key in rootDefines) {
73
+ Object.assign(injects, parseInject(vite, platform, language, source, 'uni', rootDefines[key], hasPlatformFile));
74
+ }
95
75
  }
96
76
  return injects;
97
77
  }
98
78
  exports.parseInjects = parseInjects;
99
- function parseInject(vite = true, platform, source, globalObject, define) {
79
+ function parseInject(vite = true, platform, language, source, globalObject, define, hasPlatformFile) {
100
80
  const injects = {};
101
81
  if (define === false) {
102
82
  }
103
83
  else if (typeof define === 'string') {
104
84
  // {'uni.getBatteryInfo' : '@dcloudio/uni-getbatteryinfo'}
105
- injects[globalObject + '.' + define] = vite ? source : [source, 'default'];
85
+ if (hasPlatformFile) {
86
+ injects[globalObject + '.' + define] = vite ? source : [source, 'default'];
87
+ }
106
88
  }
107
89
  else if (Array.isArray(define)) {
108
90
  // {'uni.getBatteryInfo' : ['@dcloudio/uni-getbatteryinfo','getBatteryInfo]}
109
- define.forEach((d) => {
110
- injects[globalObject + '.' + d] = [source, d];
111
- });
91
+ if (hasPlatformFile) {
92
+ define.forEach((d) => {
93
+ injects[globalObject + '.' + d] = [source, d];
94
+ });
95
+ }
112
96
  }
113
97
  else {
114
98
  const keys = Object.keys(define);
@@ -118,21 +102,56 @@ function parseInject(vite = true, platform, source, globalObject, define) {
118
102
  }
119
103
  else {
120
104
  const defineOptions = define[d];
121
- if (defineOptions[platform] !== false) {
122
- if (platform === 'app') {
123
- injects[globalObject + '.' + d] = [
124
- source,
125
- defineOptions.name || d,
126
- defineOptions.app,
127
- ];
128
- }
129
- else {
105
+ const p = platform === 'app-android' || platform === 'app-ios'
106
+ ? 'app'
107
+ : platform;
108
+ if (!(p in defineOptions)) {
109
+ if (hasPlatformFile) {
130
110
  injects[globalObject + '.' + d] = [source, defineOptions.name || d];
131
111
  }
132
112
  }
113
+ else {
114
+ if (defineOptions[p] !== false) {
115
+ if (p === 'app') {
116
+ const appOptions = defineOptions.app;
117
+ if (isPlainObject(appOptions)) {
118
+ if (language === 'javascript') {
119
+ if (appOptions.js === false) {
120
+ return;
121
+ }
122
+ }
123
+ else if (language === 'kotlin') {
124
+ if (appOptions.kotlin === false) {
125
+ return;
126
+ }
127
+ }
128
+ else if (language === 'swift') {
129
+ if (appOptions.swift === false) {
130
+ return;
131
+ }
132
+ }
133
+ }
134
+ injects[globalObject + '.' + d] = [
135
+ source,
136
+ defineOptions.name || d,
137
+ defineOptions.app,
138
+ ];
139
+ }
140
+ else {
141
+ injects[globalObject + '.' + d] = [
142
+ source,
143
+ defineOptions.name || d,
144
+ ];
145
+ }
146
+ }
147
+ }
133
148
  }
134
149
  });
135
150
  }
136
151
  return injects;
137
152
  }
138
- exports.parseInject = parseInject;
153
+ const objectToString = Object.prototype.toString;
154
+ const toTypeString = (value) => objectToString.call(value);
155
+ function isPlainObject(val) {
156
+ return toTypeString(val) === '[object Object]';
157
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-alpha-3080420230602001",
3
+ "version": "2.0.2-alpha-3080520230616001",
4
4
  "description": "uni-cli-shared",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -26,5 +26,5 @@
26
26
  "postcss-urlrewrite": "^0.2.2",
27
27
  "strip-json-comments": "^2.0.1"
28
28
  },
29
- "gitHead": "a666ad999f9275f8614f6f0974c2b14c23f85098"
29
+ "gitHead": "b72041697706bef2a2e017d02d820b9518f96eae"
30
30
  }