rexma-design 1.4.4 → 2.0.1

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.
package/package.json CHANGED
@@ -1,95 +1,63 @@
1
1
  {
2
- "id": "rexma-design",
3
2
  "name": "rexma-design",
4
- "displayName": "rexma-design",
5
- "version": "1.4.4",
6
- "description": "rexma-design",
7
- "author": "mqyun",
8
- "keywords": [
9
- "rexma-design"
10
- ],
11
- "main": "index.ts",
12
- "module": "index.ts",
13
- "repository": "",
14
- "engines": {
15
- "HBuilderX": "^3.1.0"
3
+ "version": "2.0.1",
4
+ "scripts": {
5
+ "start": "vue-cli-service serve",
6
+ "build": "vue-cli-service build",
7
+ "lint": "vue-cli-service lint",
8
+ "prepare": "husky install"
16
9
  },
17
- "dcloudext": {
18
- "type": "component-vue",
19
- "sale": {
20
- "regular": {
21
- "price": "0.00"
22
- },
23
- "sourcecode": {
24
- "price": "0.00"
25
- }
26
- },
27
- "contact": {
28
- "qq": ""
29
- },
30
- "declaration": {
31
- "ads": "",
32
- "data": "",
33
- "permissions": ""
34
- },
35
- "npmurl": ""
10
+ "sideEffects": false,
11
+ "main": "src/packages/index.ts",
12
+ "commitlint": {
13
+ "extends": [
14
+ "@commitlint/config-conventional"
15
+ ]
36
16
  },
37
- "uni_modules": {
38
- "dependencies": [],
39
- "encrypt": [],
40
- "platforms": {
41
- "cloud": {
42
- "tcb": "u",
43
- "aliyun": "u",
44
- "alipay": "u"
45
- },
46
- "client": {
47
- "Vue": {
48
- "vue2": "u",
49
- "vue3": "u"
50
- },
51
- "App": {
52
- "app-vue": "u",
53
- "app-nvue": "u",
54
- "app-uvue": "u"
55
- },
56
- "H5-mobile": {
57
- "Safari": "u",
58
- "Android Browser": "u",
59
- "微信浏览器(Android)": "u",
60
- "QQ浏览器(Android)": "u"
61
- },
62
- "H5-pc": {
63
- "Chrome": "u",
64
- "IE": "u",
65
- "Edge": "u",
66
- "Firefox": "u",
67
- "Safari": "u"
68
- },
69
- "小程序": {
70
- "微信": "u",
71
- "阿里": "u",
72
- "百度": "u",
73
- "字节跳动": "u",
74
- "QQ": "u",
75
- "钉钉": "u",
76
- "快手": "u",
77
- "飞书": "u",
78
- "京东": "u"
79
- },
80
- "快应用": {
81
- "华为": "u",
82
- "联盟": "u"
83
- }
84
- }
85
- }
86
- },
87
- "peerDependencies": {
88
- "wot-design-uni": "*",
89
- "xinhua-sdk": "*"
17
+ "lint-staged": {
18
+ "src/**/*.{html,vue,ts,cjs,json,md}": [
19
+ "prettier --write"
20
+ ]
90
21
  },
91
22
  "dependencies": {
92
23
  "crypto-js": "^4.2.0",
93
24
  "js-md5": "^0.8.3"
25
+ },
26
+ "devDependencies": {
27
+ "@commitlint/cli": "17.1.2",
28
+ "@commitlint/config-conventional": "17.1.0",
29
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
30
+ "@typescript-eslint/parser": "^5.4.0",
31
+ "@vant/auto-import-resolver": "^1.3.0",
32
+ "@vue/cli-plugin-babel": "~5.0.0",
33
+ "@vue/cli-plugin-eslint": "~5.0.0",
34
+ "@vue/cli-plugin-router": "~5.0.0",
35
+ "@vue/cli-plugin-typescript": "~5.0.0",
36
+ "@vue/cli-service": "~5.0.0",
37
+ "@vue/eslint-config-typescript": "^9.1.0",
38
+ "core-js": "^3.8.3",
39
+ "eslint": "^7.32.0",
40
+ "eslint-config-prettier": "^8.3.0",
41
+ "eslint-plugin-prettier": "^4.0.0",
42
+ "eslint-plugin-vue": "^8.0.3",
43
+ "eslint-webpack-plugin": "3.2.0",
44
+ "husky": "8.0.3",
45
+ "ky": "^1.8.1",
46
+ "lib-flexible": "^0.3.2",
47
+ "pinia": "^3.0.3",
48
+ "vant": "^4.9.20",
49
+ "vue": "^3.2.13",
50
+ "vue-router": "^4.0.3",
51
+ "xinhua-sdk": "^1.15.8",
52
+ "lint-staged": "13.3.0",
53
+ "postcss-pxtorem": "^6.1.0",
54
+ "prettier": "^2.4.1",
55
+ "prettier-plugin-organize-imports": "^4.1.0",
56
+ "sass": "^1.32.7",
57
+ "sass-loader": "^12.0.0",
58
+ "typescript": "~4.5.5",
59
+ "unplugin-auto-import": "^19.3.0",
60
+ "unplugin-vue-components": "^28.7.0",
61
+ "vue-tsc": "^2.2.10"
94
62
  }
95
63
  }
@@ -1,7 +1,6 @@
1
- import type { IXinhuaClientState } from './XinhuaClient/declaration';
2
-
3
- import { enc, mode, AES, pad } from 'crypto-js';
4
- import xh from './xh';
1
+ import { AES, enc, mode, pad } from 'crypto-js';
2
+ import xh from 'xinhua-sdk';
3
+ import type { IXinhuaClientState } from './declaration';
5
4
 
6
5
  type IGetClientSignParams = {
7
6
  key: string;
@@ -47,7 +46,7 @@ class ClientSign {
47
46
  */
48
47
  static async getClientSign(options: IGetClientSignParams) {
49
48
  const { developmentClientSign, key, offset, moduleCode } = options;
50
- if (import.meta.env.DEV && developmentClientSign) {
49
+ if (process.env.NODE_ENV === 'development' && developmentClientSign) {
51
50
  return developmentClientSign;
52
51
  }
53
52
  if (!xh.isMediaConvergenceXinhuaApp()) {
@@ -1,9 +1,8 @@
1
- import type { IXinhuaClientInitOptions, IXinhuaClientState } from './declaration';
2
-
3
- import getValueFromUA from '../getValueFromUA';
4
1
  import { md5 } from 'js-md5';
5
- import ClientSign from '../ClientSign';
6
- import xh from '../xh';
2
+ import xh from 'xinhua-sdk';
3
+ import getValueFromUA from '../getValueFromUA';
4
+ import ClientSign from './ClientSign';
5
+ import type { IXinhuaClientInitOptions, IXinhuaClientState } from './declaration';
7
6
 
8
7
  class XinhuaClient {
9
8
  /** 数据初始化是否完成 */
@@ -27,14 +26,14 @@ class XinhuaClient {
27
26
 
28
27
  private static async stateInit() {
29
28
  const initOptions = this.initOptions;
30
- if (import.meta.env.DEV && initOptions.developmentState) {
29
+ if (process.env.NODE_ENV === 'development' && initOptions.developmentState) {
31
30
  // 本地开发、配置的本地开发环境的数据
32
31
  this.state = {
33
32
  ...this.state,
34
33
  ...initOptions.developmentState,
35
34
  };
36
35
  }
37
- const isClientDebug = import.meta.env.DEV && initOptions.clientDebug;
36
+ const isClientDebug = process.env.NODE_ENV === 'development' && initOptions.clientDebug;
38
37
  if (xh.isMediaConvergenceXinhuaApp() && !isClientDebug) {
39
38
  // 客户端环境
40
39
  this.state.siteId = getValueFromUA('currentSiteId');
@@ -2,7 +2,6 @@
2
2
  * @description 从 ua 中根据 key 获取信息
3
3
  */
4
4
  function getValueFromUA(name: string) {
5
- // #ifdef H5
6
5
  const userAgent = window.navigator.userAgent;
7
6
  const userAgentArr = userAgent.split(' ');
8
7
  let uaValue = '';
@@ -16,11 +15,6 @@ function getValueFromUA(name: string) {
16
15
  }
17
16
  }
18
17
  return uaValue;
19
- // #endif
20
-
21
- // #ifndef H5
22
- return '';
23
- // #endif
24
18
  }
25
19
 
26
20
  export default getValueFromUA;
@@ -0,0 +1,2 @@
1
+ export { default as getValueFromUA } from './getValueFromUA';
2
+ export { default as XinhuaClient } from './XinhuaClient';
package/changelog.md DELETED
File without changes
@@ -1,21 +0,0 @@
1
- $prefix: 'xh-grid';
2
-
3
- .#{$prefix} {
4
- width: 100%;
5
-
6
- &-row {
7
- display: flex;
8
-
9
- &:last-child {
10
- margin-bottom: 0 !important;
11
- }
12
- }
13
-
14
- &-col {
15
- flex: 1;
16
-
17
- &:last-child {
18
- margin-right: 0 !important;
19
- }
20
- }
21
- }
@@ -1,68 +0,0 @@
1
- <template>
2
- <view class="xh-grid">
3
- <block v-for="(row, rowIndex) in renderList" :key="rowIndex">
4
- <view class="xh-grid-row" :style="{ marginBottom: gap }">
5
- <block v-for="(col, colIndex) in row" :key="colIndex">
6
- <view class="xh-grid-col" :style="{ marginRight: gap }" v-if="col">
7
- <slot :data="col"></slot>
8
- </view>
9
- <view class="xh-grid-col" :style="{ marginRight: gap }" v-else></view>
10
- </block>
11
- </view>
12
- </block>
13
- </view>
14
- </template>
15
-
16
- <script setup lang="ts">
17
- import { computed } from 'vue';
18
-
19
- type IItemInfo = Record<string, any>;
20
-
21
- type IXhGridProps = {
22
- /** 列表数据 */
23
- list: IItemInfo[];
24
- /** 间隔 */
25
- gap?: string;
26
- /** 排布方式 */
27
- mode?: 1 | 2;
28
- };
29
-
30
- const props = withDefaults(defineProps<IXhGridProps>(), {
31
- list: () => [],
32
- gap: '16rpx',
33
- mode: 1,
34
- });
35
-
36
- const renderList = computed(() => {
37
- if (props.mode === 2) {
38
- // mode 为 2 时,当数量小于等于 3 的时候,撑满行;当数量为 4 时撑满两行
39
- if (props.list.length <= 3) {
40
- return [props.list];
41
- }
42
- if (props.list.length === 4) {
43
- return [props.list.slice(0, 2), props.list.slice(2)];
44
- }
45
- }
46
- // 分割为行列的二维数组,同时补齐一行三个元素
47
- const returnList: IItemInfo[][] = [[]];
48
- props.list.forEach((item) => {
49
- const lastInfo = returnList[returnList.length - 1];
50
- if (lastInfo.length === 3) {
51
- returnList.push([]);
52
- }
53
- returnList[returnList.length - 1].push(item);
54
- });
55
- return returnList.map((row) => {
56
- if (row.length === 3) {
57
- return row;
58
- }
59
- return row.concat(Array.from({ length: 3 - row.length }).map(() => null));
60
- });
61
- });
62
-
63
- console.log(renderList.value);
64
- </script>
65
-
66
- <style lang="scss">
67
- @import './index.scss';
68
- </style>
@@ -1,363 +0,0 @@
1
- <template>
2
- <view style="position: relative">
3
- <view class="image-map-wrap" ref="imageMapWrapRef">
4
- <image
5
- :src="image"
6
- :style="{
7
- transform: `translate(${translate.x}px, ${translate.y}px) scale(${scale})`,
8
- transformOrigin: `${scaleCenter.x}px ${scaleCenter.y}px`,
9
- }"
10
- class="image"
11
- mode="heightFix"
12
- @touchstart="touchstart"
13
- @touchmove="touchmove"
14
- @touchend="touchend"
15
- @touchcancel="touchcancel"
16
- @click="onImageClick"
17
- @load="onImageLoad"
18
- ref="imageMapRef"
19
- ></image>
20
- </view>
21
- <view class="action-bar">
22
- <div class="action-item" @click="changeScale('+')">
23
- <wd-icon name="add-circle1" size="44rpx"></wd-icon>
24
- </div>
25
- <div class="action-item" @click="changeScale('-')">
26
- <wd-icon name="minus-circle" size="44rpx"></wd-icon>
27
- </div>
28
- </view>
29
- </view>
30
- </template>
31
-
32
- <script setup lang="ts">
33
- import { nextTick, ref, watch } from 'vue';
34
-
35
- type IMark = {
36
- start: [number, number];
37
- end: [number, number];
38
- [key: string]: any;
39
- };
40
-
41
- type IImageMapProps = {
42
- /** 图片地址 */
43
- image: string;
44
- /** 点的集合 */
45
- marks: IMark[];
46
- /** 默认居中展示地图 */
47
- defaultCenter?: boolean;
48
- };
49
-
50
- const props = withDefaults(defineProps<IImageMapProps>(), {
51
- defaultCenter: false,
52
- });
53
- const emit = defineEmits(['markClick']);
54
-
55
- const maxScale = 3;
56
- const minScale = 1;
57
- // 禁用双指缩放
58
- const doubleTouchDisabled = true;
59
-
60
- // 图片地图外容器实例 ref
61
- const imageMapWrapRef = ref();
62
- // 图片 ref
63
- const imageMapRef = ref();
64
- // 地图物理信息
65
- const mapInstanceInfo = ref({
66
- originWidth: 0,
67
- originHeight: 0,
68
- xRange: [0, 0],
69
- yRange: [0, 0],
70
- });
71
-
72
- // 缩放的原点
73
- const scaleCenter = ref({ x: 0, y: 0 });
74
- // 缩放比例
75
- const scale = ref(1);
76
- // 缩放的两指间距
77
- const scaleDistance = ref(0);
78
- // 滑动起始点
79
- const slideStart = ref({ x: 0, y: 0 });
80
- // 偏移量
81
- const translate = ref({ x: 0, y: 0 });
82
-
83
- /**
84
- * @description 改变缩放比例
85
- */
86
- function changeScale(type: '+' | '-') {
87
- // 获取缩放中心点
88
- const mapRect = getElRect('map');
89
- const mapWrapRect = getElRect('mapWrap');
90
- const _scaleCenter = {
91
- x: (-mapRect.x + mapWrapRect.width / 2) / scale.value,
92
- y: (-mapRect.y + mapWrapRect.height / 2) / scale.value,
93
- };
94
- let isCenterChange = false;
95
- if (
96
- Math.round(_scaleCenter.x) !== Math.round(scaleCenter.value.x) ||
97
- Math.round(_scaleCenter.y) !== Math.round(scaleCenter.value.y)
98
- ) {
99
- isCenterChange = true;
100
- }
101
- let _scale = scale.value;
102
- if (type === '+') {
103
- _scale += 0.2;
104
- }
105
- if (type === '-') {
106
- _scale -= 0.2;
107
- }
108
- if (_scale < minScale || _scale > maxScale) {
109
- return;
110
- }
111
- if (isCenterChange) {
112
- // 缩放中心点发生变化
113
- translate.value = {
114
- x: -(_scaleCenter.x - mapWrapRect.width / 2),
115
- y: -(_scaleCenter.y - mapWrapRect.height / 2),
116
- };
117
- scaleCenter.value = _scaleCenter;
118
- }
119
- scale.value = Number(_scale.toFixed(2));
120
- }
121
-
122
- /**
123
- * @description 获取元素物理信息
124
- */
125
- function getElRect(elType: 'map' | 'mapWrap'): Record<'width' | 'height' | 'x' | 'y', number> {
126
- if (elType === 'map') {
127
- return imageMapRef.value.$el.getClientRects()[0];
128
- }
129
- if (elType === 'mapWrap') {
130
- return imageMapWrapRef.value.$el.getClientRects()[0];
131
- }
132
- return {
133
- width: 0,
134
- height: 0,
135
- x: 0,
136
- y: 0,
137
- };
138
- }
139
-
140
- /**
141
- * @description 拖动开始事件
142
- */
143
- function touchstart(e: TouchEvent) {
144
- if (e.touches.length === 1) {
145
- // 单指移动
146
- slideStart.value = {
147
- x: e.touches[0].pageX,
148
- y: e.touches[0].pageY,
149
- };
150
- }
151
- if (e.touches.length === 2 && !doubleTouchDisabled) {
152
- // 双指缩放
153
- const mapRect = getElRect('map');
154
- const touchA = e.touches[0];
155
- const touchB = e.touches[1];
156
- const touchCenter = {
157
- x: (touchA.pageX + touchB.pageX) / 2,
158
- y: (touchA.pageY + touchB.pageY) / 2,
159
- };
160
- const _scaleCenter = {
161
- x: (Math.abs(mapRect.x) + touchCenter.x) / scale.value,
162
- y: (Math.abs(mapRect.y) + touchCenter.y) / scale.value,
163
- };
164
- if (translate.value.x || translate.value.y) {
165
- const preCenterDistance = {
166
- x: _scaleCenter.x - scaleCenter.value.x,
167
- y: _scaleCenter.y - scaleCenter.value.y,
168
- };
169
- translate.value = {
170
- x: translate.value.x + preCenterDistance.x,
171
- y: translate.value.y + preCenterDistance.y,
172
- };
173
- }
174
- scaleCenter.value = _scaleCenter;
175
- scaleDistance.value = Math.hypot(touchA.pageX - touchB.pageX, touchA.pageY - touchB.pageY);
176
- }
177
- }
178
-
179
- /**
180
- * @description 拖动事件
181
- */
182
- function touchmove(e: TouchEvent) {
183
- if (e.touches.length === 1) {
184
- // 单指移动
185
- const touch = e.touches[0];
186
- const xDistance = Math.abs(touch.pageX - slideStart.value.x);
187
- const yDistance = Math.abs(touch.pageY - slideStart.value.y);
188
- let _translateX = translate.value.x;
189
- let _translateY = translate.value.y;
190
- const xRange = mapInstanceInfo.value.xRange;
191
- const yRange = mapInstanceInfo.value.yRange;
192
- if (touch.pageX > slideStart.value.x) {
193
- // 向右移动
194
- _translateX += xDistance;
195
- }
196
- if (touch.pageX < slideStart.value.x) {
197
- // 向左移动
198
- _translateX -= xDistance;
199
- }
200
- if (touch.pageY > slideStart.value.y) {
201
- // 向下移动
202
- _translateY += yDistance;
203
- }
204
- if (touch.pageY < slideStart.value.y) {
205
- // 向上移动
206
- _translateY -= yDistance;
207
- }
208
- if (_translateX >= xRange[0] && _translateX <= xRange[1]) {
209
- // 左右移动边界
210
- translate.value.x = _translateX;
211
- }
212
- if (_translateY >= yRange[0] && _translateY <= yRange[1]) {
213
- // 上下移动边界
214
- translate.value.y = _translateY;
215
- }
216
- slideStart.value = {
217
- x: e.touches[0].pageX,
218
- y: e.touches[0].pageY,
219
- };
220
- }
221
- if (e.touches.length === 2 && !doubleTouchDisabled) {
222
- // 双指缩放
223
- const touchA = e.touches[0];
224
- const touchB = e.touches[1];
225
- const _distanceValue = Math.hypot(touchA.pageX - touchB.pageX, touchA.pageY - touchB.pageY);
226
- if (_distanceValue > scaleDistance.value) {
227
- // 放大
228
- const _scale = scale.value + scaleDistance.value / _distanceValue / 10;
229
- scale.value = _scale <= maxScale ? _scale : maxScale;
230
- } else {
231
- // 缩小
232
- const _scaleValue = scale.value - _distanceValue / scaleDistance.value / 10;
233
- scale.value = _scaleValue < 1 ? 1 : _scaleValue;
234
- }
235
- scaleDistance.value = _distanceValue;
236
- }
237
- }
238
-
239
- function touchend() {}
240
-
241
- function touchcancel() {}
242
-
243
- /**
244
- * @description 点击图片区域
245
- */
246
- function onImageClick(e: TouchEvent) {
247
- if (e.type !== 'click') {
248
- return;
249
- }
250
- const mapRect = getElRect('map');
251
- const clickDetail = {
252
- // @ts-ignore
253
- x: e.detail.x,
254
- // @ts-ignore
255
- y: e.detail.y,
256
- };
257
- const clickPoint = {
258
- x: clickDetail.x - mapRect.x,
259
- y: clickDetail.y - mapRect.y,
260
- };
261
- const originScale = mapRect.width / mapInstanceInfo.value.originWidth;
262
- const originPoint = {
263
- x: clickPoint.x / originScale,
264
- y: clickPoint.y / originScale,
265
- };
266
- console.log(originPoint, '点击的原始位置');
267
- const currentMark = (props.marks || []).find((item) => {
268
- return (
269
- originPoint.x >= item.start[0] &&
270
- originPoint.x <= item.end[0] &&
271
- originPoint.y >= item.start[1] &&
272
- originPoint.y <= item.end[1]
273
- );
274
- });
275
- if (currentMark) {
276
- emit('markClick', currentMark);
277
- }
278
- }
279
-
280
- /**
281
- * @description 图片加载完成
282
- */
283
- function onImageLoad(e: any) {
284
- const mapRect = getElRect('map');
285
- const mapWrapRect = getElRect('mapWrap');
286
- mapInstanceInfo.value = {
287
- originWidth: e.detail.width,
288
- originHeight: e.detail.height,
289
- xRange: [-(mapRect.width - mapWrapRect.width), 0],
290
- yRange: [-(mapRect.height - mapWrapRect.height), 0],
291
- };
292
- if (props.defaultCenter) {
293
- translate.value.x = -(mapRect.width - mapWrapRect.width) / 2;
294
- }
295
- }
296
-
297
- watch([scale, translate], function () {
298
- nextTick(function () {
299
- const mapRect = getElRect('map');
300
- const mapWrapRect = getElRect('mapWrap');
301
- const xRange = [
302
- -(mapRect.width - mapWrapRect.width + mapRect.x - translate.value.x),
303
- -(mapRect.x - translate.value.x),
304
- ];
305
- const yRange = [
306
- -(mapRect.height - mapWrapRect.height + mapRect.y - translate.value.y),
307
- -(mapRect.y - translate.value.y),
308
- ];
309
-
310
- mapInstanceInfo.value.xRange = xRange;
311
- mapInstanceInfo.value.yRange = yRange;
312
-
313
- if (translate.value.x < xRange[0]) {
314
- translate.value.x = xRange[0];
315
- }
316
- if (translate.value.x > xRange[1]) {
317
- translate.value.x = xRange[1];
318
- }
319
- if (translate.value.y < yRange[0]) {
320
- translate.value.y = yRange[0];
321
- }
322
- if (translate.value.y > yRange[1]) {
323
- translate.value.y = yRange[1];
324
- }
325
- });
326
- });
327
- </script>
328
-
329
- <style scoped lang="scss">
330
- .image-map-wrap {
331
- width: 100%;
332
- height: 100%;
333
- font-size: 0;
334
- overflow: hidden;
335
-
336
- .image {
337
- height: 100%;
338
- }
339
- }
340
-
341
- $actionSize: 80rpx;
342
-
343
- .action-bar {
344
- position: absolute;
345
- bottom: 80rpx;
346
- right: 60rpx;
347
- background: rgba(#000, 0.45);
348
- height: $actionSize;
349
- display: flex;
350
- border-radius: 30rpx;
351
- color: rgba(#fff, 0.9);
352
- padding: 0 14rpx;
353
-
354
- .action-item {
355
- width: $actionSize;
356
- height: $actionSize;
357
- display: flex;
358
- align-items: center;
359
- justify-content: center;
360
- cursor: pointer;
361
- }
362
- }
363
- </style>
@@ -1,12 +0,0 @@
1
- export type UploadType = 'image' | 'video' | 'file';
2
-
3
- export type IModelValue = {
4
- url: string;
5
- [key: string]: any;
6
- };
7
-
8
- export const uploadTypeTextMap = new Map<UploadType, string>([
9
- ['image', '图片'],
10
- ['video', '视频'],
11
- ['file', '文件'],
12
- ]);
@@ -1,46 +0,0 @@
1
- $prefix: 'xh-upload';
2
-
3
- .#{$prefix} {
4
- position: relative;
5
- width: 156rpx;
6
- height: 156rpx;
7
- background: rgba(0, 0, 0, 0.02);
8
- border-radius: 8rpx;
9
- cursor: pointer;
10
- display: flex;
11
- flex-direction: column;
12
- align-items: center;
13
- justify-content: center;
14
- border: 1px dashed #d9d9d9;
15
-
16
- &-title {
17
- margin-top: 12rpx;
18
- font-size: 24rpx;
19
- color: #999;
20
- line-height: 34rpx;
21
- }
22
-
23
- &-extra {
24
- position: absolute;
25
- top: 0;
26
- left: 0;
27
- right: 0;
28
- bottom: 0;
29
-
30
- .icon-remove {
31
- position: absolute;
32
- top: 8rpx;
33
- right: 8rpx;
34
- width: 30rpx;
35
- height: 30rpx;
36
- border-radius: 50%;
37
- background: rgba(0, 0, 0, 0.2);
38
- color: #fff;
39
- display: flex;
40
- align-items: center;
41
- justify-content: center;
42
- padding-top: 2rpx;
43
- cursor: pointer;
44
- }
45
- }
46
- }
@@ -1,33 +0,0 @@
1
- import type { UploadType } from '../declaration';
2
- import xh from '../../../utils/xh';
3
-
4
- /**
5
- * @description 选择客户端文件
6
- */
7
- export function clientChooseFile(type: UploadType): Promise<any[]> {
8
- return new Promise((resolve) => {
9
- if (type === 'image') {
10
- xh.chooseImage({
11
- count: 1,
12
- success(res) {
13
- resolve(res?.list || []);
14
- },
15
- });
16
- }
17
- if (type === 'video') {
18
- xh.chooseVideo({
19
- success(res) {
20
- resolve([res]);
21
- },
22
- });
23
- }
24
- if (type === 'file') {
25
- xh.chooseFile({
26
- // isMultiple: Number(maxLength > 1),
27
- success(res) {
28
- resolve(res?.data);
29
- },
30
- });
31
- }
32
- });
33
- }
@@ -1,132 +0,0 @@
1
- <template>
2
- <view class="xh-upload" @click="onXhUploadClick">
3
- <block v-if="uploading">
4
- <wd-loading size="48rpx" v-if="uploading" />
5
- <text class="xh-upload-title">上传中</text>
6
- </block>
7
- <block v-else>
8
- <block v-if="props.modelValue?.url">
9
- <image
10
- :src="props.modelValue.url"
11
- mode="aspectFit"
12
- style="width: 100%; height: 100%"
13
- ></image>
14
- <view class="xh-upload-extra">
15
- <view class="icon-remove" @click.stop="removeFile">
16
- <wd-icon name="close" size="18rpx"></wd-icon>
17
- </view>
18
- </view>
19
- </block>
20
- <block v-else>
21
- <wd-icon name="add" size="40rpx" color="#999"></wd-icon>
22
- <text class="xh-upload-title">{{ uploadTip }}</text>
23
- </block>
24
- </block>
25
- </view>
26
- </template>
27
-
28
- <script setup lang="ts">
29
- import { ref, computed } from 'vue';
30
-
31
- import { type UploadType, type IModelValue, uploadTypeTextMap } from './declaration';
32
- import xh from '../../utils/xh';
33
- import XinhuaClient from '../../utils/XinhuaClient';
34
- import { clientChooseFile } from './utils';
35
-
36
- type IXhUploadProps = {
37
- /** 标题 */
38
- title?: string;
39
- /** 允许上传的文件类型 */
40
- acceptFileType?: UploadType | UploadType[] | Partial<Record<UploadType, string[]>>;
41
- /** 上传接口请求配置 */
42
- requestConfig: {
43
- /** 接口地址 */
44
- url: string;
45
- /** 字段名称 */
46
- name?: string;
47
- /** 其他请求参数 */
48
- params?: Record<string, any>;
49
- };
50
- /** 格式化上传结果 */
51
- formatResponse: (res: any) => IModelValue;
52
- /** 是否需要加签 */
53
- requestSign?: boolean;
54
- /** 值 */
55
- modelValue?: IModelValue;
56
- };
57
-
58
- const props = withDefaults(defineProps<IXhUploadProps>(), {
59
- acceptFileType: () => 'image',
60
- requestSign: true,
61
- });
62
- const emit = defineEmits(['update:modelValue']);
63
- // 上传状态
64
- const uploading = ref(false);
65
- const uploadTip = computed(() => {
66
- if (props.title) {
67
- return props.title;
68
- }
69
- if (typeof props.acceptFileType === 'string') {
70
- return `上传${uploadTypeTextMap.get(props.acceptFileType)}`;
71
- }
72
- // todo: acceptFileType 配置非字符串时所展示的文案
73
- return '';
74
- });
75
-
76
- /**
77
- * @description 点击上传卡片
78
- */
79
- function onXhUploadClick() {
80
- if (!props.acceptFileType || uploading.value) {
81
- return;
82
- }
83
- if (typeof props.acceptFileType === 'string') {
84
- onChooseFile(props.acceptFileType);
85
- return;
86
- }
87
- if (props.acceptFileType instanceof Array) {
88
- if (props.acceptFileType.length === 1) {
89
- onChooseFile(props.acceptFileType[0]);
90
- } else {
91
- // todo: 展示选择弹窗
92
- }
93
- return;
94
- }
95
- // todo: 对象配置
96
- }
97
-
98
- /**
99
- * @description 调用客户端方法选择文件、上传
100
- * @param fileType
101
- */
102
- async function onChooseFile(fileType: UploadType) {
103
- const chooseList = await clientChooseFile(fileType);
104
- uploading.value = true;
105
- let signParams = props.requestConfig.params;
106
- if (props.requestSign) {
107
- signParams = await XinhuaClient.getSignRequestParams(props.requestConfig.params || {});
108
- }
109
- xh.uploadFile({
110
- url: props.requestConfig.url,
111
- name: props.requestConfig.name || 'file',
112
- params: signParams,
113
- files: chooseList?.map((item) => item.path),
114
- success: (res) => {
115
- const uploadRes = props.formatResponse(res);
116
- emit('update:modelValue', uploadRes);
117
- uploading.value = false;
118
- },
119
- });
120
- }
121
-
122
- /**
123
- * @description 移除上传后的文件
124
- */
125
- function removeFile() {
126
- emit('update:modelValue', null);
127
- }
128
- </script>
129
-
130
- <style lang="scss">
131
- @import './index.scss';
132
- </style>
package/index.ts DELETED
@@ -1 +0,0 @@
1
- export { default as XinhuaClient } from './utils/XinhuaClient/index';
package/utils/xh.ts DELETED
@@ -1,3 +0,0 @@
1
- import xh from 'xinhua-sdk';
2
-
3
- export default xh;
File without changes