hookehuyr

创建活动页面上传图片功能联调

<!--
* @Date: 2022-09-26 21:52:25
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-09-27 09:09:44
* @LastEditTime: 2022-10-17 13:40:57
* @FilePath: /swx/src/components/activity-editor.vue
* @Description: 文件描述
-->
<template>
<view class="editor-box">
<view class="editor-box-header" v-if="showTabBar">
<view class="operate-box" :data-uploadImageURL="uploadImageURL" @tap="_addImage">
<view class="operate-box" @tap="_addImage">
<text class="iconfont icon-image"></text>
</view>
<view class="operate-box" @tap="_addItalic">
......@@ -43,8 +43,8 @@
</view>
</view>
<view class="editor-box-content">
<editor id="editor" :name="name" :placeholder="placeholder" @ready="_onEditorReady"
@input="_onInputting" :show-img-resize="true"></editor>
<editor id="editor" :name="name" :placeholder="placeholder" @ready="_onEditorReady" @input="_onInputting"
:show-img-resize="true"></editor>
</view>
</view>
</template>
......@@ -55,10 +55,11 @@ import { ref } from 'vue'
</script>
<script>
import Taro from '@tarojs/taro'
import BASE_URL from '@/utils/config';
export default {
props: ['showTabBar', 'placeholder', 'name', 'uploadImageURL'],
data () {
props: ['showTabBar', 'placeholder', 'name'],
data() {
return {
}
......@@ -82,23 +83,27 @@ export default {
title: '上传中',
mask: true
});
_this._uploadImage(res.tempFilePaths[0], event.currentTarget.dataset.uploadimageurl);
// _this._uploadImage(res.tempFilePaths[0], event.currentTarget.dataset.uploadimageurl);
_this._uploadImage(res.tempFilePaths[0], BASE_URL + '/admin/?m=srv&a=upload');
}
});
},
_uploadImage: function (tempFilePath, uploadImageURL) {
let _this = this;
wx.uploadFile({
filePath: tempFilePath,
name: 'image',
url: uploadImageURL,
filePath: tempFilePath,
name: 'file',
header: {
'content-type': 'multipart/form-data',
},
success: function (res) {
res = JSON.parse(res.data);
let upload_data = JSON.parse(res.data);
wx.hideLoading({
success: () => {
if (res.code === 200) {
if (res.statusCode === 200) {
_this.editorCtx.insertImage({
src: res.data
src: upload_data.data.src
});
} else {
wx.showToast({
......
<!--
* @Date: 2022-09-21 16:04:10
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-10-14 17:35:45
* @LastEditTime: 2022-10-17 13:56:03
* @FilePath: /swx/src/pages/createActivity/index.vue
* @Description: 创建活动页面
-->
......@@ -282,6 +282,7 @@ import { getCurrentPageUrl, getCurrentPageParam } from "@/utils/weapp";
import request from '../../utils/request';
import Taro from '@tarojs/taro'
import mixin from '../../utils/mixin';
import BASE_URL from '@/utils/config';
const message = ref('');
const message1 = ref('');
......@@ -307,9 +308,32 @@ const has_image = ref(false)
const uploader_image = ref('')
const afterRead = (event) => {
const { file } = event.detail;
console.warn(file);
// 获取上传URL
wx.uploadFile({
url: BASE_URL + '/admin/?m=srv&a=upload',
filePath: file.url,
name: 'file',
header: {
'content-type': 'multipart/form-data',
},
success: function (res) {
let upload_data = JSON.parse(res.data);
wx.hideLoading({
success: () => {
if (res.statusCode === 200) {
has_image.value = true;
uploader_image.value = file.url
uploader_image.value = upload_data.data.src;
} else {
wx.showToast({
icon: 'error',
title: '服务器错误,稍后重试!',
mask: true
})
}
},
});
}
});
}
const removeUploadImage = () => {
has_image.value = false;
......