提交 f7657580 authored 作者: 刘旭's avatar 刘旭

解决上传修改

上级 6f0199cf
......@@ -34,17 +34,14 @@
</template>
<script lang="ts" setup>
import { ref, reactive } from 'vue';
import { ref } from 'vue';
import { getHavePage, getPageComponent } from '@/services/api';
import headerVue from '@/pages/header/index.vue';
import uploadPreview from './uploadPreview.vue';
let color = ref('#a27443');
let imageData = ref([] as any);
let videoData = ref();
// 通用模板初始数据
let currencyPage = ref();
let popup = ref();
let openSetting = () => {
uni.navigateTo({
......@@ -52,33 +49,6 @@ let openSetting = () => {
});
};
// 上传图片
let uploadImage = () => {
uni.chooseImage({
success(res: any) {
imageData.value = res.tempFiles;
console.log(res);
uni.navigateTo({
url: `./uploadImage?imageData=${encodeURIComponent(JSON.stringify(res.tempFiles))}&imageArr=${encodeURIComponent(JSON.stringify(res.tempFilePaths))}`
});
}
});
};
// 上传视频
let uploadVideo = () => {
uni.chooseVideo({
sourceType: ['camera', 'album'],
success(res: any) {
console.log(res);
videoData.value = res;
uni.navigateTo({
url: `./uploadVideo?videoData=${encodeURIComponent(JSON.stringify(res))}`
});
}
});
};
// 通用
let currencyTemplate = async () => {
let res: any = await getPageComponent({ pageId: currencyPage.value[0].id });
......@@ -100,8 +70,9 @@ let initHavePage = async () => {
title: '加载中...'
});
let res: any = await getHavePage();
console.log(res, '模板数据');
if (res.data) {
uni.hideLoading();
}
currencyPage.value = res.data.currencyPage;
uni.$emit('previewData', { previewData: res.data });
};
......
......@@ -37,7 +37,6 @@ onLoad((options: any) => {
// 通用定制模板
let currencyPage = JSON.parse(options.currencyPage);
templateId.value = JSON.parse(options.id);
console.log(currencyPage);
for (let s in currencyPage) {
imageVideoData.value.push({
path: baseURL + downUrl + currencyPage[s].pageComponent,
......@@ -76,11 +75,23 @@ let uploadImage = () => {
uni.chooseImage({
success(res: any) {
for (let i = 0; i < res.tempFilePaths.length; i++) {
uni.uploadFile({
url: baseURL + '/wx/storage/upload',
filePath: res.tempFilePaths[i],
name: 'file',
success: (res: any) => {
let data = JSON.parse(res.data).data;
imageVideoData.value.push({
path: res.tempFilePaths[i],
type: res.tempFiles[i].type,
path: baseURL + data.url,
type: data.type,
sort: imageVideoData.value.length
});
console.log(imageVideoData.value);
},
fail(res: any) {
console.log(res);
}
});
}
}
});
......@@ -104,10 +115,22 @@ let uploadVideo = () => {
uni.chooseVideo({
sourceType: ['camera', 'album'],
success(res: any) {
uni.uploadFile({
url: baseURL + '/wx/storage/upload',
filePath: res.tempFilePath,
name: 'file',
success: (res: any) => {
let data = JSON.parse(res.data).data;
imageVideoData.value.push({
path: res.tempFilePath,
type: res.tempFile.type,
sort: imageVideoData.value.length + 1
path: baseURL + data.url,
type: data.type,
sort: imageVideoData.value.length
});
console.log(imageVideoData.value);
},
fail(res: any) {
console.log(res);
}
});
}
});
......@@ -124,72 +147,38 @@ let uploadVideo = () => {
}
};
let kuaidata = ref ()
let save = () => {
if (templateId.value) {
new Promise((resolve: any, reject: any) => {
let idArr: any = [];
console.log(imageVideoData.value);
for (let key in imageVideoData.value) {
if (imageVideoData.value[key].path.split('.').length == 1) {
uni.uploadFile({
url: baseURL + '/wx/storage/upload',
filePath: imageVideoData.value[key].path,
name: 'file',
success: (res: any) => {
// console.log(imageVideoData.value, key);
// console.log(JSON.parse(res.data).data.key);
if (res.data.errno != 502) {
idArr.push({
pageComponent: JSON.parse(res.data).data.key,
sort: imageVideoData.value[key].sort
});
}
},
fail(res: any) {
console.log(res);
}
});
} else {
let str = imageVideoData.value[key].path.split('/');
idArr.push({
pageComponent: str[str.length - 1],
sort: imageVideoData.value[key].sort
});
}
if (Number(key) == imageVideoData.value.length - 1) {
console.log(idArr, 'resolve');
resolve(idArr);
}
}
}).then((idArr: any) => {
console.log(idArr);
if (type.value == 'currency') {
console.log(idArr, '添加');
setTimeout(() => {
templateAdd({ pageComponentList: idArr }).then((res: any) => {
if (res.data.errno == 0) {
uni.hideLoading();
// imageVideoData.value = [];
// close();
imageVideoData.value = [];
close();
}
});
}, 50);
} else {
kuaidata.value = idArr
console.log('編輯', idArr);
setTimeout(() => {
updateCustomPage({ id: templateId.value, pageComponentList: kuaidata.value }).then((res: any) => {
updateCustomPage({ id: templateId.value, pageComponentList: idArr }).then((res: any) => {
if (res.data.errno == 0) {
console.log('你快一点吗!', idArr);
uni.hideLoading();
// imageVideoData.value = [];
// close();
imageVideoData.value = [];
close();
}
});
}, 50);
}
});
} else {
// 空白
let idArr: any = [];
......@@ -269,8 +258,20 @@ let replaceImg = (index: number) => {
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['camera', 'album'], //从相册选择
success: function(res: any) {
imageVideoData.value[index]['path'] = res.tempFiles[0].path;
console.log(res);
uni.uploadFile({
url: baseURL + '/wx/storage/upload',
filePath: res.tempFilePaths[0],
name: 'file',
success: (res: any) => {
let data = JSON.parse(res.data).data;
imageVideoData.value[index]['path'] = baseURL + data.url;
console.log(imageVideoData.value);
},
fail(res: any) {
console.log(res);
}
});
}
});
}
......@@ -282,12 +283,23 @@ let replaceImg = (index: number) => {
confirmText: '确认',
content: '确认替换视频?',
success: (res: any) => {
console.log(res);
if (res.confirm) {
uni.chooseVideo({
sourceType: ['camera', 'album'], //从相册选择
success: function(res: any) {
imageVideoData.value[index]['path'] = res.tempFiles[0].path;
uni.uploadFile({
url: baseURL + '/wx/storage/upload',
filePath: res.tempFilePath,
name: 'file',
success: (res: any) => {
let data = JSON.parse(res.data).data;
imageVideoData.value[index]['path'] = baseURL + data.url;
console.log(imageVideoData.value);
},
fail(res: any) {
console.log(res);
}
});
}
});
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论