rexma-design 1.0.0 → 1.0.2
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/components/xh-upload/declaration.ts +6 -0
- package/components/xh-upload/index.scss +37 -0
- package/components/xh-upload/utils/index.ts +32 -0
- package/components/xh-upload/xh-upload.vue +102 -0
- package/index.ts +2 -0
- package/package.json +5 -2
- package/utils/XinhuaClient/declaration.ts +3 -0
- package/utils/XinhuaClient/index.ts +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
|
|
33
|
+
&.extra-bg {
|
|
34
|
+
background: rgba(0, 0, 0, 0.4);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 (['image', 'image-camera'].includes(type)) {
|
|
10
|
+
xh.chooseImage({
|
|
11
|
+
success(res) {
|
|
12
|
+
resolve(res?.list || []);
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (type === 'video') {
|
|
17
|
+
xh.chooseVideo({
|
|
18
|
+
success(res) {
|
|
19
|
+
resolve([res]);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (type === 'file') {
|
|
24
|
+
xh.chooseFile({
|
|
25
|
+
// isMultiple: Number(maxLength > 1),
|
|
26
|
+
success(res) {
|
|
27
|
+
resolve(res?.data);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
</block>
|
|
15
|
+
<block v-else>
|
|
16
|
+
<wd-icon name="add" size="40rpx" color="#999"></wd-icon>
|
|
17
|
+
<text class="xh-upload-title">{{ title }}</text>
|
|
18
|
+
</block>
|
|
19
|
+
</block>
|
|
20
|
+
</view>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script setup lang="ts">
|
|
24
|
+
import type { UploadType, IModelValue } from './declaration';
|
|
25
|
+
import xh from '../../utils/xh';
|
|
26
|
+
import XinhuaClient from '../../utils/XinhuaClient';
|
|
27
|
+
import { clientChooseFile } from './utils';
|
|
28
|
+
|
|
29
|
+
type IXhUploadProps = {
|
|
30
|
+
/** 标题 */
|
|
31
|
+
title?: string;
|
|
32
|
+
/** 允许上传的文件类型 */
|
|
33
|
+
acceptFileType?: UploadType | UploadType[] | Partial<Record<UploadType, string[]>>;
|
|
34
|
+
/** 上传接口请求配置 */
|
|
35
|
+
requestConfig: {
|
|
36
|
+
/** 接口地址 */
|
|
37
|
+
url: string;
|
|
38
|
+
/** 字段名称 */
|
|
39
|
+
name?: string;
|
|
40
|
+
/** 其他请求参数 */
|
|
41
|
+
params?: Record<string, any>;
|
|
42
|
+
};
|
|
43
|
+
/** 格式化上传结果 */
|
|
44
|
+
formatResponse: (res: any) => IModelValue;
|
|
45
|
+
/** 是否需要加签 */
|
|
46
|
+
requestSign?: boolean;
|
|
47
|
+
/** 值 */
|
|
48
|
+
modelValue?: IModelValue;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const props = withDefaults(defineProps<IXhUploadProps>(), {
|
|
52
|
+
title: '上传图片',
|
|
53
|
+
acceptFileType: () => ['image'],
|
|
54
|
+
requestSign: true,
|
|
55
|
+
});
|
|
56
|
+
const emit = defineEmits(['update:modelValue']);
|
|
57
|
+
|
|
58
|
+
const uploading = ref(false);
|
|
59
|
+
|
|
60
|
+
function onXhUploadClick() {
|
|
61
|
+
if (!props.acceptFileType) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (typeof props.acceptFileType === 'string') {
|
|
65
|
+
onChooseFile(props.acceptFileType);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (props.acceptFileType instanceof Array) {
|
|
69
|
+
if (props.acceptFileType.length === 1) {
|
|
70
|
+
onChooseFile(props.acceptFileType[0]);
|
|
71
|
+
} else {
|
|
72
|
+
// todo: 展示选择弹窗
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// todo: 对象配置
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function onChooseFile(fileType: UploadType) {
|
|
80
|
+
const chooseList = await clientChooseFile(fileType);
|
|
81
|
+
uploading.value = true;
|
|
82
|
+
let signParams = props.requestConfig.params;
|
|
83
|
+
if (props.requestSign) {
|
|
84
|
+
signParams = await XinhuaClient.getSignRequestParams(props.requestConfig.params || {});
|
|
85
|
+
}
|
|
86
|
+
xh.uploadFile({
|
|
87
|
+
url: props.requestConfig.url,
|
|
88
|
+
name: props.requestConfig.name || 'file',
|
|
89
|
+
params: signParams,
|
|
90
|
+
files: chooseList?.map((item) => item.path),
|
|
91
|
+
success: (res) => {
|
|
92
|
+
const uploadRes = props.formatResponse(res);
|
|
93
|
+
emit('update:modelValue', uploadRes);
|
|
94
|
+
uploading.value = false;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
</script>
|
|
99
|
+
|
|
100
|
+
<style lang="scss">
|
|
101
|
+
@import './index.scss';
|
|
102
|
+
</style>
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
"id": "rexma-design",
|
|
3
3
|
"name": "rexma-design",
|
|
4
4
|
"displayName": "rexma-design",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.2",
|
|
6
6
|
"description": "rexma-design",
|
|
7
7
|
"author": "mqyun",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"rexma-design"
|
|
10
10
|
],
|
|
11
|
+
"main": "index.ts",
|
|
12
|
+
"module": "index.ts",
|
|
11
13
|
"repository": "",
|
|
12
14
|
"engines": {
|
|
13
15
|
"HBuilderX": "^3.1.0"
|
|
@@ -83,7 +85,8 @@
|
|
|
83
85
|
}
|
|
84
86
|
},
|
|
85
87
|
"peerDependencies": {
|
|
86
|
-
"rexma-cli": "*"
|
|
88
|
+
"rexma-cli": "*",
|
|
89
|
+
"wot-design-uni": "*"
|
|
87
90
|
},
|
|
88
91
|
"dependencies": {
|
|
89
92
|
"crypto-js": "^4.2.0"
|
|
@@ -34,7 +34,7 @@ class XinhuaClient {
|
|
|
34
34
|
...initOptions.developmentState,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
if (xh.isMediaConvergenceXinhuaApp()) {
|
|
37
|
+
if (xh.isMediaConvergenceXinhuaApp() && !initOptions.clientDebug) {
|
|
38
38
|
// 客户端环境
|
|
39
39
|
this.state.siteId = getValueFromUA('currentSiteId');
|
|
40
40
|
this.state.userId = getValueFromUA('userId');
|