Kaynağa Gözat

utils增加uuid,修改云上传

ming 3 yıl önce
ebeveyn
işleme
5c4f53551a

+ 2 - 2
components/fs-avatar-group/fs-avatar-group.vue

@@ -15,12 +15,12 @@ const props = defineProps({
 	border: Boolean,
 })
 
-const paddingLeft = computed(() => -props.margin + 'rpx')
+const marginLeft = computed(() => -props.margin + 'rpx')
 provide('avatarGroup', props)
 </script>
 
 <style lang="scss" scoped>
 .fs-avatar-group{
-	padding-left: v-bind(paddingLeft);
+	margin-left: v-bind(marginLeft);
 }
 </style>

+ 2 - 2
components/fs-avatar/fs-avatar.vue

@@ -77,11 +77,11 @@ const props = defineProps({
 	fixed: Boolean,
 	right: {
 		type: String,
-		default: '30rpx'
+		default: '40rpx'
 	},
 	bottom: {
 		type: String,
-		default: '30rpx'
+		default: '60rpx'
 	},
 	defaultErrorImg: {
 		type: String,

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "fs-uni",
-  "version": "2.3.1",
+  "version": "2.3.2",
   "description": "",
   "main": "main.js",
   "dependencies": {

+ 27 - 3
utils/utils.js

@@ -4,6 +4,29 @@ export default {
 	isHttp(path) {
 		return path.startsWith('http') || path.startsWith('https')
 	},
+	uuid(len = 16) {
+		const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
+		const uuid = []
+	
+		if (len) {
+			// 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位
+			for (let i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * chars.length]
+		} else {
+			let r
+			// rfc4122标准要求返回的uuid中,某些位为固定的字符
+			uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
+			uuid[14] = '4'
+	
+			for (let i = 0; i < 36; i++) {
+				if (!uuid[i]) {
+					r = 0 | Math.random() * 16
+					uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]
+				}
+			}
+		}
+		
+		return uuid.join('')
+	},
 	upload(data) {
 		return uni.uploadFile({
 			url: this.isHttp(data.url) ? data.url : config.apiBaseUrl + data.url,
@@ -28,10 +51,11 @@ export default {
 		return this[methods](chooseParam).then(file => {
 			file.filePaths.forEach((filePath, index) => {
 				if (isCloud) {
+					const fileArr = filePath.split('.')
 					uploadArr.push(this.uploadCloud({
-						filePath, 
-						cloudPath: file.tempFiles[index].name, 
-						fileType: file.tempFiles[index].type
+						filePath,
+						cloudPath: this.uuid() + '.' + fileArr[fileArr.length - 1],
+						fileType: (methods === 'chooseImage' ? 'image/' : 'video/') + fileArr[fileArr.length - 1]
 					}).then(res => {
 						if (res.success) {
 							return {