Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
swx_weapp
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2022-10-17 14:33:37 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
52f1d2cf965c4c9606b406b9303f4dd34c679bab
52f1d2cf
1 parent
ed73b96c
创建活动页面上传图片功能联调
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
16 deletions
src/components/activity-editor.vue
src/pages/createActivity/index.vue
src/components/activity-editor.vue
View file @
52f1d2c
<!--
* @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.
c
ode === 200) {
if (res.
statusC
ode === 200) {
_this.editorCtx.insertImage({
src:
res.data
src:
upload_data.data.src
});
} else {
wx.showToast({
...
...
src/pages/createActivity/index.vue
View file @
52f1d2c
<!--
* @Date: 2022-09-21 16:04:10
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-10-1
4 17:35:45
* @LastEditTime: 2022-10-1
7 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);
has_image.value = true;
uploader_image.value = file.url
// 获取上传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 = upload_data.data.src;
} else {
wx.showToast({
icon: 'error',
title: '服务器错误,稍后重试!',
mask: true
})
}
},
});
}
});
}
const removeUploadImage = () => {
has_image.value = false;
...
...
Please
register
or
login
to post a comment