增加上传方法、投诉页面

This commit is contained in:
TOP糯米 2023-03-11 22:44:15 +08:00
parent 12fde350d2
commit 54a93f9c5a
8 changed files with 241 additions and 1 deletions

View File

@ -225,6 +225,47 @@ function serviceActions() {
});
}
function chooseImage(count) {
return new Promise((resolve, reject) => {
let tempFiles = [];
// #ifdef H5
uni.chooseImage({
count: count,
success(r) {
r.tempFiles.forEach((item, index) => {
tempFiles.push({
path: r.tempFilePaths[index],
size: item.size,
});
});
resolve(tempFiles);
},
fail(e) {
reject(e);
}
});
// #endif
// #ifdef MP-WEIXIN
uni.chooseMedia({
count: count,
mediaType: ["image"],
success(r) {
r.tempFiles.forEach(item => {
tempFiles.push({
path: item.tempFilePath,
size: item.size,
});
});
resolve(tempFiles);
},
fail(e) {
reject(e);
}
});
// #endif
});
}
export default {
time,
datetime,
@ -239,4 +280,5 @@ export default {
toast,
formatNumber,
serviceActions,
chooseImage,
}

View File

@ -3,6 +3,7 @@ import user from "@/core/models/user";
import worker from "@/core/models/worker";
import service from "@/core/models/service";
import cart from "@/core/models/cart";
import system from "@/core/models/system";
export default {
order,
@ -10,4 +11,5 @@ export default {
worker,
service,
cart,
system,
}

37
src/core/models/system.js Normal file
View File

@ -0,0 +1,37 @@
import Vue from "vue"
let prototype = Vue.prototype;
export default {
/**
* 上传文件
*/
upload(path) {
return new Promise((resolve, reject) => {
prototype.$upload({
api: "system.uploadFile",
path: path
}).then(response => {
if (response.code == 1) {
return resolve(response.data);
}
return reject(response.msg);
});
});
},
/**
* 提交投诉
*/
submitComplaint(data) {
return new Promise((resolve, reject) => {
prototype.$request({
api: "system.complaint",
data: data,
}).then(response => {
if (response.code == 1) {
return resolve();
}
return reject(response.msg);
}).catch(e => { });
});
}
}

48
src/core/upload.js Normal file
View File

@ -0,0 +1,48 @@
import Vue from "vue"
let prototype = Vue.prototype;
function findApi(name) {
let pos = name.indexOf('.');
if (pos > 0) {
let temp, arr = name.split('.');
for (let i = 0; i < arr.length; i++) {
if (i == 0) {
temp = prototype.$apis[arr[i]] || {};
} else {
temp = temp[arr[i]] || {};
}
}
return temp;
}
return name;
}
let upload = async (args) => {
const rule = findApi(args.api || '');
if (JSON.stringify(rule) === "{}") {
throw "找不到API" + args.api;
}
(rule.showLoading) && uni.showLoading({
title: "上传中"
});
let [error, response] = await uni.uploadFile({
url: prototype.$config.root + rule.url,
filePath: args.path,
name: args.name || 'file',
formData: args.data || {},
});
(rule.showLoading) && uni.hideLoading();
if (error) {
prototype.$utils.toast('网络错误');
throw "网络错误";
}
return Promise.resolve(JSON.parse(response.data));
}
export default upload

View File

@ -3,6 +3,7 @@ import App from './App'
import store from "./store/index"
import request from './core/request'
import upload from './core/upload'
import test from './core/libs/test'
import event from './core/libs/event'
import utils from './core/libs/utils'
@ -14,6 +15,7 @@ import './static/iconfont/iconfont.css'
Vue.use({
install(Vue, options) {
Vue.prototype.$request = request
Vue.prototype.$upload = upload
Vue.prototype.$test = test
Vue.prototype.$event = event
Vue.prototype.$utils = utils

View File

@ -85,6 +85,12 @@
"navigationBarTitleText": "我的"
}
},
{
"path": "pages/member/complaint",
"style": {
"navigationBarTitleText": "投诉"
}
},
{
"path": "pages/member/setting",
"style": {

View File

@ -0,0 +1,103 @@
<template>
<app-layout title="投诉">
<view class="common-form-container">
<view class="input-item">
<view class="title-box">
<text>标题</text>
</view>
<view class="input-box">
<input class="input" v-model="title" placeholder="请输入标题" placeholder-class="placeholder-style-3" />
</view>
</view>
<view class="textarea-item">
<view class="title-box">
<text>内容</text>
</view>
<view class="textarea-box">
<textarea
v-model="content"
class="textarea"
placeholder="请输入投诉内容"
placeholder-class="placeholder-style-3"
/>
</view>
</view>
<view class="upload-item">
<view v-if="image" class="image-box" @click="chooseImage">
<image class="image" :src="image" mode="aspectFill" />
</view>
<view v-else class="image-box upload" @click="chooseImage">
<text class="iconfont icon-shangchuantupian"></text>
<text class="text">上传图片</text>
</view>
</view>
</view>
<view class="common-save-form-btn">
<view class="btn" @click="submit">提交</view>
</view>
</app-layout>
</template>
<script>
import AppLayout from "@/components/layout/layout";
export default {
name: "member-omplaint",
data() {
return {
title: "",
image: "",
content: "",
};
},
components: {
AppLayout,
},
onLoad() {},
onShow() {},
onReady() {},
onReachBottom() {},
onPullDownRefresh() {},
methods: {
/**
* 上传图片
*/
chooseImage() {
this.$utils.chooseImage(1).then((tempFiles) => {
this.$models.system.upload(tempFiles[0].path).then((response) => {
this.image = response.img;
});
});
},
/**
* 提交
*/
submit() {
this.$models.system
.submitComplaint({
title: this.title,
imgs: this.image,
desc: this.content,
})
.then((response) => {
console.log(response);
})
.catch((e) => {
this.$utils.toast(e);
});
},
},
};
</script>
<style lang="less" scoped>
.common-form-container {
z-index: 10;
position: relative;
.title-box {
font-weight: normal;
}
.upload-item {
padding-bottom: 30rpx;
}
}
</style>

View File

@ -24,7 +24,7 @@
<text class="title">我的地址</text>
<text class="iconfont icon-jinru more"></text>
</view>
<view class="widget-item">
<view class="widget-item" @click="toPage('/pages/member/complaint')">
<text class="iconfont icon-tousu icon"></text>
<text class="title">意见投诉</text>
<text class="iconfont icon-jinru more"></text>