diff --git a/src/components/AiImage/AiImage.vue b/src/components/AiImage/AiImage.vue
index aafb06b..bce6957 100644
--- a/src/components/AiImage/AiImage.vue
+++ b/src/components/AiImage/AiImage.vue
@@ -31,10 +31,7 @@ export default {
preview: Boolean,
link: Boolean,
miniapp: Boolean,
- file: {
- default: () => {
- }
- }
+ file: {default: () => ({})}
},
methods: {
...mapActions(['previewFile', 'injectJWeixin']),
diff --git a/src/components/AiUploader/AiUploader.vue b/src/components/AiUploader/AiUploader.vue
index 1dc0816..ccfc204 100644
--- a/src/components/AiUploader/AiUploader.vue
+++ b/src/components/AiUploader/AiUploader.vue
@@ -11,7 +11,7 @@
@@ -64,16 +64,22 @@ export default {
fileId: String,
mediaId: String,
def: {default: () => []},
- action: {default: '/admin/file/add'},
+ action: String,
preview: Boolean,
size: {default: 10 * 1024 * 1024},
disabled: Boolean,
},
computed: {
...mapState(['token']),
- errorImage() {
- return this.$cdn + 'file.png'
- },
+ errorImage: v => v.$cdn + 'file.png',
+ api() {
+ if (this.action) return this.action
+ else return {
+ image: '/admin/file/add',
+ file: '/admin/file/add',
+ video: '/admin/file/addVideo',
+ }[this.type]
+ }
},
watch: {
def: {
@@ -105,19 +111,17 @@ export default {
upload(wait) {
let count = this.limit - (this.fileList?.length || 0)
if (count > 0) {
- let params = {
+ const params = {
count,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
- success: (res) => {
+ success: res => {
let count = this.fileList?.length + (res.tempFiles?.length || res.tempFile ? 1 : 0)
if (count > this.limit && this.limit !== 1) {
return this.$u.toast(`不能超过${this.limit}个`)
}
- if (res.tempFiles) {
- res.tempFiles?.map((item) => {
- this.uploadFile(item)
- })
+ if (res.tempFiles?.length > 0) {
+ res.tempFiles.map(this.uploadFile)
} else if (res?.tempFile) {
this.uploadFile(res.tempFile)
}
@@ -125,9 +129,9 @@ export default {
}
typeof wait == 'function' && wait()
if (this.type == 'image') {
- uni.chooseImage(params)
+ uni.chooseMedia({...params, mediaType: ['image']})
} else if (this.type == 'video') {
- uni.chooseMedia(params)
+ uni.chooseMedia({...params, mediaType: ['video']})
} else {
uni.chooseFile(params)
}
@@ -144,38 +148,43 @@ export default {
this.$emit('manual', img)
uni.hideLoading()
} else {
+ const filePath = img.path || img.tempFilePath
uni.uploadFile({
- url: this.$instance.defaults.baseURL + this.action,
- filePath: img.path,
+ url: this.$instance.defaults.baseURL + this.api,
+ filePath,
name: 'file',
header: {
'Content-Type': 'multipart/form-data',
- Authorization: uni.getStorageSync('token'),
+ Authorization: this.token,
},
success: response => {
const res = JSON.parse(response.data)
if (res?.data) {
this.$emit('data', res.data)
this.$u.toast('上传成功!')
- if (this.action.endsWith('/file/add')) {
- this.fileList.push({url: res.data?.[0]?.split(";")?.[0], id: res.data?.[0]?.split(";")?.[1]})
- } else if (this.action == '/admin/file/add2') {
+ if (!this.action) {//默认组件接口
+ if (this.type == 'image') {
+ const [image = "",] = res.data
+ this.fileList.push({url: image.split(";")[0], id: image.split(";")?.[1]})
+ } else if (this.type == 'video') {
+ const [video = "", thumb = ""] = res.data
+ this.fileList.push({url: video.split(";")[0], id: video.split(";")?.[1], thumb: thumb.split(";")[0]})
+ }
+ } else if (this.api == '/admin/file/add2') {
let info = res.data
this.$emit('update:fileId', info?.id)
this.fileList.push(res.data)
- } else if (this.action == '/admin/file/add-portrait') {
+ } else if (this.api == '/admin/file/add-portrait') {
this.fileList.push({url: res.data?.split(";")?.[0], id: res.data?.split(";")?.[1]})
}
- this.$emit("update:def", this.fileList)
this.$emit("input", this.fileList)
+ this.$emit("update:def", this.fileList)
} else {
this.$u.toast(res.msg)
}
},
- fail: err => {
- console.error(err)
- },
- complete: () => uni.hideLoading()
+ fail: console.error,
+ complete: uni.hideLoading
})
}
@@ -212,9 +221,10 @@ export default {
border-radius: 50%;
overflow: hidden;
background-color: #fff;
+ height: 40px;
}
- image {
+ image,video {
width: 29vw;
height: 29vw;
}