Kaynağa Gözat

upload增加插槽

ming 3 yıl önce
ebeveyn
işleme
2401e07f59
3 değiştirilmiş dosya ile 30 ekleme ve 20 silme
  1. 23 9
      components/fs-upload/fs-upload.vue
  2. 1 1
      package.json
  3. 6 10
      utils/utils.js

+ 23 - 9
components/fs-upload/fs-upload.vue

@@ -13,20 +13,26 @@
 				:src="formatPath(item)"
 				:shape="shape"
 				:size="size"
+				:width="width"
+				:height="height"
 				radius
 				@click="handlePreview(formatPath(item))">
 			</fs-avatar>
 			<video v-else :src="formatPath(item)" controls class="fs-file-video"></video>
 		</view>
-		<view class="fs-file-box" v-if="modelValue.length < count">
-			<fs-avatar
-				:shape="shape"
-				:size="size"
-				radius
-				bgColor="#EBEFF5"
-				@click="upload">
-				<fs-icon type="icon-plus" size="50px"></fs-icon>
-			</fs-avatar>
+		<view class="fs-file-box" @click="upload" v-if="modelValue.length < count">
+			<slot>
+				<fs-avatar
+					:shape="shape"
+					:size="size"
+					:width="width"
+					:height="height"
+					radius
+					bgColor="#EBEFF5"
+				>
+					<fs-icon type="icon-plus" size="50px"></fs-icon>
+				</fs-avatar>
+			</slot>
 		</view>
 	</view>
 </template>
@@ -75,6 +81,14 @@ const props = defineProps({
 		type: String,
 		default: '150rpx'
 	},
+	width: {
+		type: String,
+		default: '150rpx'
+	},
+	height: {
+		type: String,
+		default: '150rpx'
+	},
 	formData: {
 		type: Object,
 		default() {

+ 1 - 1
package.json

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

+ 6 - 10
utils/utils.js

@@ -52,10 +52,14 @@ export default {
 			file.filePaths.forEach((filePath, index) => {
 				if (isCloud) {
 					const fileArr = filePath.split('.')
+					// 只在h5可用
+					const fileType = file.tempFiles[index].type || 'image/png'
+					const suffix = fileArr.length >= 2 ? fileArr[fileArr.length - 1] : fileType.split('/')[1]
+					
 					uploadArr.push(this.uploadCloud({
 						filePath,
-						cloudPath: this.uuid() + '.' + fileArr[fileArr.length - 1],
-						fileType: (methods === 'chooseImage' ? 'image/' : 'video/') + fileArr[fileArr.length - 1]
+						cloudPath: this.uuid() + '.' + suffix,
+						fileType: (methods === 'chooseImage' ? 'image/' : 'video/') + suffix
 					}).then(res => {
 						if (res.success) {
 							return {
@@ -121,12 +125,4 @@ export default {
 	chooseAndUploadVideo(chooseParam, uploadParam, isCloud) {
 		return this.chooseAndUpload('chooseVideo',chooseParam, uploadParam, isCloud)
 	},
-	authLogin(cb) {
-		if (!uni.getStorageSync('token')) {
-			return uni.navigateTo({
-				url: '/modules/common/login/login'
-			})
-		}
-		cb && cb()
-	}
 }