|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
|
- <view class="page">
|
|
|
+ <view class="page">
|
|
|
<view class="nav-bar">
|
|
|
<view class="left">
|
|
|
<view class="uni-btn-icon" @click="goBack"></view>
|
|
@@ -41,7 +41,7 @@
|
|
|
<view class="optionalWorks" @click="onManage">
|
|
|
<view class="title">
|
|
|
可选作品
|
|
|
- <text v-if="id < 1">(图片或作品必选一个发布)</text>
|
|
|
+ <text v-if="id < 1">(图片或作品必选一个发布)</text>
|
|
|
</view>
|
|
|
<view class="selectLeft">
|
|
|
<text class="prompt" v-if="id > 1">已选择一个作品</text>
|
|
@@ -322,7 +322,13 @@ export default {
|
|
|
if (this.is_submit > 0) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+ // 构建图片字符串
|
|
|
+ let img_str = '';
|
|
|
+ if (this.img_list.length > 0) {
|
|
|
+ for (let i = 0; i < this.img_list.length; i++) {
|
|
|
+ img_str += this.img_list[i] + "|";
|
|
|
+ }
|
|
|
+ }
|
|
|
// 校验图片数量和作品选择
|
|
|
if (this.img_list.length < 1 && !this.selectedWork.id) {
|
|
|
uni.showToast({
|
|
@@ -330,35 +336,32 @@ export default {
|
|
|
icon: 'none'
|
|
|
});
|
|
|
return;
|
|
|
- }else{
|
|
|
- // 校验图片字符串有效性(可选,因为已经检查了图片数量)
|
|
|
- if (!img_str || img_str.trim().length < 2) {
|
|
|
- uni.showToast({
|
|
|
- title: '请确保至少上传一张有效图片作为封面',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- // 校验图片数量不超过 5 张
|
|
|
- if (this.img_list.length > 5) {
|
|
|
- uni.showToast({
|
|
|
- title: '最多只能上传 5 张图片',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 构建图片字符串
|
|
|
- let img_str = '';
|
|
|
- if (this.img_list.length > 0) {
|
|
|
- for (let i = 0; i < this.img_list.length; i++) {
|
|
|
- img_str += this.img_list[i] + "|";
|
|
|
+ } else {
|
|
|
+ if (!this.selectedWork.id) {
|
|
|
+ // 校验图片字符串有效性(可选,因为已经检查了图片数量)
|
|
|
+ if (!img_str || img_str.trim().length < 2) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '请确保至少上传一张有效图片作为封面',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 校验图片数量不超过 5 张
|
|
|
+ if (this.img_list.length > 5) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '最多只能上传 5 张图片',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
let that = this;
|
|
|
this.is_submit = 1;
|
|
|
uni.request({
|
|
@@ -434,13 +437,13 @@ export default {
|
|
|
async checkRights(sourceType) {
|
|
|
try {
|
|
|
let hasPermission = false;
|
|
|
-
|
|
|
+
|
|
|
if (sourceType === 'camera') {
|
|
|
hasPermission = await permission.request(permission.PermissionType.CAMERA, {
|
|
|
title: '“萌创星球”想访问你的相机',
|
|
|
describe: '萌创星球想访问您的摄像头,便于拍摄获取图片来与其他用户进行交流'
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
if (!hasPermission) {
|
|
|
uni.showToast({
|
|
|
title: '未获得相机权限',
|
|
@@ -453,7 +456,7 @@ export default {
|
|
|
title: '“萌创星球”想访问你的照片图库',
|
|
|
describe: '萌创星球想访问您本地照片图库,便于获取图片来与其他用户进行交流'
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
if (!hasPermission) {
|
|
|
uni.showToast({
|
|
|
title: '未获得相册权限',
|
|
@@ -462,9 +465,9 @@ export default {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 权限获取成功后,继续执行上传
|
|
|
- this.upload2(type, sourceType);
|
|
|
+ this.upload2('list', sourceType);
|
|
|
} catch (error) {
|
|
|
console.error('权限检查失败:', error);
|
|
|
uni.showToast({
|
|
@@ -480,7 +483,7 @@ export default {
|
|
|
count: 5,
|
|
|
sizeType: ['compressed'],
|
|
|
sourceType: [sourceType],
|
|
|
- success: function(res) {
|
|
|
+ success: function (res) {
|
|
|
console.log('res:', res)
|
|
|
for (let index = 0; index < res.tempFilePaths.length; index++) {
|
|
|
let filepath = "";
|