uni-feedback.vue 8.3 KB
Newer Older
芊里 已提交
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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
<template>
	<view class="page">
		<view class="feedback-title">
			<text>问题和意见</text>
			<text class="feedback-quick" @tap="chooseMsg">快速键入</text>
		</view>
		<view class="feedback-body"><textarea placeholder="请详细描述你的问题和意见..." v-model="sendDate.content"
				class="feedback-textare"></textarea></view>
		<view class="feedback-title"><text>图片(选填,提供问题截图,总大小10M以下)</text></view>
		<view class="feedback-body feedback-uploader">
			<view class="uni-uploader">
				<view class="uni-uploader-head">
					<view class="uni-uploader-title">点击预览图片</view>
					<view class="uni-uploader-info">{{ imageList.length }}/5</view>
				</view>
				<view class="uni-uploader-body">
					<view class="uni-uploader__files">
						<block v-for="(image, index) in imageList" :key="index">
							<view class="uni-uploader__file" style="position: relative;">
								<image class="uni-uploader__img" :src="image" @tap="previewImage(index)"></image>
								<view class="close-view" @click="close(index)">x</view>
							</view>
						</block>
						<view class="uni-uploader__input-box" v-show="imageList.length < 5">
							<view class="uni-uploader__input" @tap="chooseImg"></view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="feedback-title"><text>联系方式</text></view>
		<view class="feedback-body"><input class="feedback-input" v-model="sendDate.contact"
				placeholder="(选填,方便我们联系你 )" /></view>
		<view class="feedback-title feedback-star-view">
			<text>应用评分</text>
			<view class="feedback-star-view">
				<uni-rate v-model="sendDate.score" color="#bbb"></uni-rate>
			</view>
		</view>
		<button type="default" class="feedback-submit" @tap="send">提交</button>
		<view class="feedback-title"><text>用户反馈的结果可在app打包后于DCloud开发者中心查看</text></view>
	</view>
</template>

<script>
	const db = uniCloud.database();
	const dbCmd = db.command;
	export default {
		data() {
			return {
				msgContents: ['界面显示错乱', '启动缓慢,卡出翔了', 'UI无法直视,丑哭了', '偶发性崩溃'],
				stars: [1, 2, 3, 4, 5],
				imageList: [],
				sendDate: {
					score: 0,
					content: '',
					contact: ''
				}
			};
		},
		onLoad() {
			// #ifdef APP-PLUS
			this.deviceInfo = {
				appid: plus.runtime.appid,
				imei: plus.device.imei, //设备标识
				p: plus.os.name === 'Android' ? 'a' : 'i', //平台类型,i表示iOS平台,a表示Android平台。
				md: plus.device.model, //设备型号
				app_version: plus.runtime.version,
				plus_version: plus.runtime.innerVersion, //基座版本号
				os: plus.os.version,
				net: '' + plus.networkinfo.getCurrentType()
			};
			//#endif
			this.deviceInfo = uni.getSystemInfo();
			// #ifndef APP-PLUS
			//#endif
			this.sendDate = Object.assign(this.deviceInfo, this.sendDate);
		},
		methods: {
			/**
			 * 关闭图片
			 * @param {Object} e
			 */
			close(e) {
				this.imageList.splice(e, 1);
			},

			/**
			 * 快速输入
			 */
			chooseMsg() {
				uni.showActionSheet({
					itemList: this.msgContents,
					success: res => {
						this.sendDate.content = this.msgContents[res.tapIndex];
					}
				});
			},

			/**
			 * 选择图片
			 */
			chooseImg() {
				//选择图片
				uni.chooseImage({
					sourceType: ['camera', 'album'],
					sizeType: 'compressed',
					count: 5 - this.imageList.length,
					success: res => {
						this.imageList = this.imageList.concat(res.tempFilePaths);
					}
				});
			},

			/**
			 * 评分
			 * @param {Object} e
			 */
			chooseStar(e) {
				//点击评星
				this.sendDate.score = e;
			},
			/**
			 * 预览图片
			 * @param {Object} index
			 */
			previewImage(index) {
				uni.previewImage({
					urls: this.imageList,
					current: this.imageList[index]
				});
			},

			/**
			 * 提交
			 */
			send() {
				//发送反馈
				if (this.sendDate.content.length === 0) {
					uni.showModal({
						content: '请输入问题和意见',
						showCancel: false
					});
					return;
				}
				uni.showLoading({
					title: '上传中...'
				});
				let imgs = this.imageList.map((value, index) => {
					return {
						name: 'images' + index,
						uri: value
					};
				});
				// TODO 服务端限制上传文件一次最大不超过 2M, 图片一次最多不超过5张
				this.request(this.sendDate, imgs)
					.then(res => {
						console.log(res);
						if(res.success){
							this.sendDate.content = '';
							this.imageList = [];
							return uni.showToast({
								title: '反馈成功',
								icon: 'none'
							});
						}
						uni.showToast({
							title: `err${res.result?.code}:${res.result?.message}`,
							icon: 'none'
						});
					})
					.catch(err => {
						console.log(err);
					})
					.finally(()=>{
						uni.hideLoading();
					})
			},

			/**
			 * 发送请求到后台
			 */
			async request(sendDate, imgs) {
				let cloud_list = [];
				for (let i = 0; i < imgs.length; i++) {
					let res = await uniCloud.uploadFile({
						filePath: imgs[i].uri,
						cloudPath: 'feedback.jpg',
						onUploadProgress: function(progressEvent) {}
					})
					cloud_list.push(res.fileID);
				}
				console.log('cloud_', cloud_list);
				return db.collection('opendb-feedback').add({
						// ...sendDate,
						 "create_date": Date.now(),
						    "content": this.sendDate.content,
						    "mobile": this.sendDate.contact,
						imgs: cloud_list
					})
			}
		}
	};
</script>

<style>
	page {
		background-color: #efeff4;
	}

	.input-view {
		font-size: 28rpx;
	}

	.close-view {
		text-align: center;
		line-height: 14px;
		height: 16px;
		width: 16px;
		border-radius: 50%;
		background: #ff5053;
		color: #ffffff;
		position: absolute;
		top: -6px;
		right: -4px;
		font-size: 12px;
	}
芊里 已提交
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
	/* 上传 */
	.uni-uploader {
		flex: 1;
		flex-direction: column;
	}
	.uni-uploader-head {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
	.uni-uploader-info {
		color: #B2B2B2;
	}
	.uni-uploader-body {
		margin-top: 16rpx;
	}
	.uni-uploader__files {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
	}
	.uni-uploader__file {
		margin: 10rpx;
		width: 210rpx;
		height: 210rpx;
	}
	.uni-uploader__img {
		display: block;
		width: 210rpx;
		height: 210rpx;
	}
	.uni-uploader__input-box {
		position: relative;
		margin:10rpx;
		width: 208rpx;
		height: 208rpx;
		border: 2rpx solid #D9D9D9;
	}
	.uni-uploader__input-box:before,
	.uni-uploader__input-box:after {
		content: " ";
		position: absolute;
		top: 50%;
		left: 50%;
		-webkit-transform: translate(-50%, -50%);
		transform: translate(-50%, -50%);
		background-color: #D9D9D9;
	}
	.uni-uploader__input-box:before {
		width: 4rpx;
		height: 79rpx;
	}
	.uni-uploader__input-box:after {
		width: 79rpx;
		height: 4rpx;
	}
	.uni-uploader__input-box:active {
		border-color: #999999;
	}
	.uni-uploader__input-box:active:before,
	.uni-uploader__input-box:active:after {
		background-color: #999999;
	}
	.uni-uploader__input {
		position: absolute;
		z-index: 1;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		opacity: 0;
	}
	/*问题反馈*/
	.feedback-title {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx;
		color: #8f8f94;
		font-size: 28rpx;
	}
	.feedback-star-view.feedback-title {
		justify-content: flex-start;
		margin: 0;
	}
	.feedback-quick {
		position: relative;
		padding-right: 40rpx;
	}
	.feedback-quick:after {
		font-family: uniicons;
		font-size: 40rpx;
		content: '\e581';
		position: absolute;
		right: 0;
		top: 50%;
		color: #bbb;
		-webkit-transform: translateY(-50%);
		transform: translateY(-50%);
	}
	.feedback-body {
		background: #fff;
	}
	.feedback-textare {
		height: 200rpx;
		font-size: 34rpx;
		line-height: 50rpx;
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx 30rpx 0;
	}
	.feedback-input {
		font-size: 34rpx;
		height: 50rpx;
		min-height: 50rpx;
		padding: 15rpx 20rpx;
		line-height: 50rpx;
	}
	.feedback-uploader {
		padding: 22rpx 20rpx;
	}
	.feedback-star {
		font-family: uniicons;
		font-size: 40rpx;
		margin-left: 6rpx;
	}
	.feedback-star-view {
		margin-left: 20rpx;
	}
	.feedback-star:after {
		content: '\e408';
	}
	.feedback-star.active {
		color: #FFB400;
	}
	.feedback-star.active:after {
		content: '\e438';
	}
	.feedback-submit {
		background: #007AFF;
		color: #FFFFFF;
		margin: 20rpx;
	}
芊里 已提交
372
</style>