suggest.vue
4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<template>
<view style="background-color: #F5F7FC; align-items: auto;">
<view style="align-items: center; display: flex;
justify-content: space-between; background-color:white; margin-top: 3vh;">
<image src="../../static/common/black_icon_back.png"
style="width: 35rpx; height: 35rpx; padding: 25rpx;"
v-on:click="onBack()" />
<text style="color: black;">问题反馈</text>
<text style="color: #298BF3; font-size: 18; margin-right: 35rpx; " v-on:click="commit()">提交</text>
</view>
<input class="uni-input" type="text" focus placeholder="欢迎提交您宝贵的建议" style="background-color:white; margin-top: 20rpx; padding: 35rpx;
height: 20;" v-model="suggest_content" />
</view>
</template>
<script>
import http from "@/utils/http";
export default {
data() {
return {
suggest_content: "",
imageList: []
}
},
methods: {
onBack() {
uni.navigateBack()
},
async commit() {
console.log("commit")
if (this.suggest_content.length < 5) {
uni.showToast({
icon: "none",
title: "最短为 5 个字符",
});
return;
}
let query_data = `mutation{
user_suggest_info(content:${JSON.stringify(this.suggest_content)})
}`;
if (this.imageList.length > 0) {
query_data = `mutation{
user_suggest_info(content:${JSON.stringify(this.suggest_content)}
,images:${JSON.stringify(this.imageList)})
}`;
}
console.log(query_data)
let result = await http.gql({
query: query_data
})
console.info(result);
//处理返回请求
if (result && result.data && result.data.user_suggest_info &&
!result.data.user_suggest_info.error) {
uni.showToast({
icon: "none",
title: "提交成功",
});
uni.navigateBack()
} else {
uni.showToast({
icon: "none",
title: "提交失败",
});
}
},
chooseImg() {
let _this = this;
uni.chooseImage({
count: 1, //最多可以选择的图片张数,默认9
sourceType: ['album'], //album 从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项
sizeType: ['original'], //original 原图,compressed 压缩图,默认二者都有
success(res) {
console.log('选择图片完成', res)
// 调用上传图片的接口
let path = res.tempFilePaths[0];
_this.imgToBase64(path).then((base64) => {
let buffer = Buffer.from(base64, "base64");
let size = buffer.length / 1024 / 1024;
if (size > 5) {
uni.showToast({
icon: "none",
title: "图片文件最大不能超过5MB!",
});
return;
}
_this.imageList.push(base64);
});
},
fail() {
console.log('失败', err);
},
complete() {
console.log('结束');
},
})
},
previewImage(index) {
uni.previewImage({
urls: this.imageList,
current: this.imageList[index],
});
},
clear(index) {
this.imageList.splice(index, 1);
},
imgToBase64(data) {
return new Promise((resolve, reject) => {
pathToBase64(data)
.then((base64) => {
resolve(base64);
})
.catch((error) => {
console.error(error);
reject(error);
});
});
},
}
}
</script>
<style>
.head-bg {
width: 100%;
height: 20%;
}
</style>