ucenter.vue 9.2 KB
Newer Older
L
213  
linju 已提交
1 2
<template>
	<view class="center">
DCloud_JSON's avatar
DCloud_JSON 已提交
3
		<view class="userInfo" @click="toEdit">
L
213  
linju 已提交
4
			<image class="logo-img" :src="login ? (userInfo.avatar || avatarUrl) :avatarUrl"></image>
芊里 已提交
5
			<view class="logo-title">
L
123  
linju 已提交
6
				<text class="uer-name">{{login ? userInfo.nickname||userInfo.username||userInfo.mobile : '未登录'}}</text>
L
213  
linju 已提交
7 8
				<text class="go-login-navigat-arrow navigat-arrow" v-if="!login">&#xe65e;</text>
			</view>
L
123  
linju 已提交
9
		</view>
L
213  
linju 已提交
10
		<uni-grid class="grid" :column="5" :showBorder="false" :square="true">
芊里 已提交
11 12 13
			<uni-grid-item class="item" v-for="(item,index) in gridList" @click.native="tapGrid(index)">
				<uni-icons class="icon" color="#5d5e64" :type="item.icon" size="28"></uni-icons>
				<text class="text">{{item.text}}</text>
L
213  
linju 已提交
14 15 16
			</uni-grid-item>
		</uni-grid>
		<uni-list class="center-list" v-for="(sublist , index) in ucenterList">
L
123  
linju 已提交
17 18 19 20 21 22
			<uni-list-item v-for="item in sublist" :title="item.title" link :rightText="item.rightText"
				:clickable="true" :to="item.to" @click="ucenterListClick(item)">
				<view v-if="item.showBadge" class="item-footer" slot="footer">
					<text class="item-footer-text">{{item.rightText}}</text>
					<view class="item-footer-badge"></view>
				</view>
芊里 已提交
23
			</uni-list-item>
24
		</uni-list>
L
213  
linju 已提交
25 26 27 28 29 30 31 32
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
芊里 已提交
33 34 35 36
	import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
	import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';

	const db = uniCloud.database();
芊里 已提交
37
	const dbCollectionName = 'uni-id-scores';
L
213  
linju 已提交
38 39 40
	export default {
		data() {
			return {
芊里 已提交
41
				avatarUrl: '/static/uni-center/logo.png',
L
213  
linju 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
				gridList: [{
						"text": "文字1",
						"icon": "chat"
					},
					{
						"text": "文字2",
						"icon": "cloud-upload"
					},
					{
						"text": "文字3",
						"icon": "contact"
					},
					{
						"text": "文字4",
						"icon": "download"
					},
					{
						"text": "文字5",
						"icon": "paperplane"
					}
				],
				ucenterList: [
芊里 已提交
64 65 66 67 68 69 70
					[
						// #ifdef APP-PLUS
						{
							title: '去评分',
							event: 'gotoMarket'
						},
						// #endif
L
123  
linju 已提交
71 72
						{
							title: '阅读过的文章',
芊里 已提交
73
							to: '/uni_modules/uni-news-favorite/pages/uni-news-favorite/list',
L
123  
linju 已提交
74 75
						}, {
							title: '我的积分',
芊里 已提交
76 77 78 79
							to: '',
							event: 'getScore'
						}
					],
L
213  
linju 已提交
80
					[{
L
123  
linju 已提交
81 82
						title: '问题与反馈',
						to: '/uni_modules/uni-feedback/pages/opendb-feedback/list' // /pages/ucenter/uni-feedback/uni-feedback uni_modules/uni-feedback/pages/opendb-feedback/list
DCloud_JSON's avatar
DCloud_JSON 已提交
83 84 85
					}, {
						title: '设置',
						to: '/pages/ucenter/settings/settings'
DCloud_JSON's avatar
123  
DCloud_JSON 已提交
86 87 88
					}, {
						title: '关于',
						to: '/pages/ucenter/about/about'
L
123  
linju 已提交
89
					}]
L
213  
linju 已提交
90 91 92
				]
			}
		},
芊里 已提交
93
		onLoad() {
芊里 已提交
94
			//#ifdef APP-PLUS
芊里 已提交
95 96 97 98 99 100
			this.ucenterList[this.ucenterList.length - 1].unshift({
				title: '检查更新',
				rightText: this.appVersion.version + '-' + this.appVersion.versionCode,
				event: 'checkVersion',
				showBadge: this.appVersion.hasNew
			})
芊里 已提交
101
			//#endif
L
123  
linju 已提交
102
		},
L
213  
linju 已提交
103 104 105 106
		computed: {
			...mapGetters({
				userInfo: 'user/info',
				login: 'user/hasLogin'
芊里 已提交
107 108
			})
			// #ifdef APP-PLUS
DCloud_JSON's avatar
DCloud_JSON 已提交
109
			,appVersion() {
芊里 已提交
110 111
				return getApp().appVersion
			}
芊里 已提交
112
			// #endif
L
213  
linju 已提交
113
		},
114 115 116 117
		methods: {
			...mapMutations({
				setUserInfo: 'user/login'
			}),
L
123  
linju 已提交
118
			toSettings() {
119
				uni.navigateTo({
L
123  
linju 已提交
120
					url: "/pages/ucenter/settings/settings"
121
				})
L
123  
linju 已提交
122
			},
L
213  
linju 已提交
123 124 125 126 127 128 129 130
			/**
			 * 个人中心项目列表点击事件
			 */
			ucenterListClick(item) {
				if (!item.to && item.event) {
					this[item.event]();
				}
			},
芊里 已提交
131
			async checkVersion() {
DCloud_JSON's avatar
123  
DCloud_JSON 已提交
132 133 134 135 136 137 138 139
				let res = await callCheckVersion()
				console.log(res);
				if(res.result.code == 0){
					uni.showToast({
						title: res.result.message,
						icon: 'none'
					});
				}
L
123  
linju 已提交
140
				checkUpdate()
L
213  
linju 已提交
141
			},
DCloud_JSON's avatar
DCloud_JSON 已提交
142 143
			toEdit() {
				console.log('点击编辑信息');
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
				// uni.navigateTo({
				// 	url: '/uni_modules/uni-id-users/pages/uni-id-users/edit'
				// })
				const token = uni.getStorageSync('uni_id_token')
				if(token){
					uni.chooseImage({
						count:1,
						success:(res)=> {
							// 头像剪裁尺寸
							let options = {
								width:600,
								height:600
							}
							// 剪裁并上传头像
							uni.navigateTo({
								url:'/pages/ucenter/edit/uploadCutImageToUnicloud?path=' + res.tempFilePaths[0] + `&options=${JSON.stringify(options)}`,
								animationType:"fade-in",
								events:{
									uploadAvatarAfter:({url})=>{
										console.log(url);
										// 使用 clientDB 提交数据
										db.collection('uni-id-users').where('_id==$env.uid').update({avatar:url}).then((res) => {
											console.log(res);
											uni.showToast({
												icon: 'none',
												title: '修改成功'
											})
											this.setUserInfo({avatar:url});
										}).catch((err) => {
											uni.showModal({
												content: err.message || '请求服务失败',
												showCancel: false
											})
										}).finally(() => {
											uni.hideLoading()
										})
									}
								}
							});
						}
					})
				}else{
					uni.navigateTo({
						url:'/uni_modules/uni-login-page/pages/index/index'
					})
				}
190
			},
L
123  
linju 已提交
191
			tapGrid(index) {
192
				uni.showToast({
L
123  
linju 已提交
193
					title: '你点击了,第' + (index + 1) + '',
194 195
					icon: 'none'
				});
196 197 198 199
			},
			/**
			 * 去应用市场评分
			 */
芊里 已提交
200
			gotoMarket() {
201 202 203 204
				// #ifdef APP-PLUS
				if (uni.getSystemInfoSync().platform == "ios") {
					// 这里填写appstore应用id
					let appstoreid = 'id1417078253';
L
123  
linju 已提交
205
					plus.runtime.openURL("itms-apps://" + 'itunes.apple.com/cn/app/wechat/' + appstoreid + '?mt=8');
206 207 208
				}
				if (uni.getSystemInfoSync().platform == "android") {
					var Uri = plus.android.importClass("android.net.Uri");
L
123  
linju 已提交
209 210 211 212 213
					var uri = Uri.parse("market://details?id=" + plus.runtime.appid);
					var Intent = plus.android.importClass('android.content.Intent');
					var intent = new Intent(Intent.ACTION_VIEW, uri);
					var main = plus.android.runtimeMainActivity();
					main.startActivity(intent);
214 215
				}
				// #endif
芊里 已提交
216 217 218 219 220 221 222 223 224 225 226 227
			},
			/**
			 * 获取积分信息
			 */
			getScore() {
				if (!this.userInfo) return uni.showToast({
					title: '请登录后查看积分',
					icon: 'none'
				});
				uni.showLoading({
					mask: true
				})
芊里 已提交
228
				db.collection(dbCollectionName).where('user_id == $env.uid').field('score,balance').get().then((res) => {
芊里 已提交
229
					const data = res.result.data[0];
230
					let msg = '';
芊里 已提交
231
					msg = data ? ('当前积分为' + data.balance) : '当前无积分';
芊里 已提交
232
					uni.showToast({
芊里 已提交
233
						title: msg,
芊里 已提交
234 235 236 237 238 239 240 241 242 243
						icon: 'none'
					});
				}).catch((err) => {
					uni.showModal({
						content: err.message || '请求服务失败',
						showCancel: false
					})
				}).finally(() => {
					uni.hideLoading()
				})
L
213  
linju 已提交
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
			}
		}
	}
</script>

<style>
	/* #ifndef APP-PLUS-NVUE */
	@font-face {
		font-family: texticons;
		font-weight: normal;
		font-style: normal;
		src: url('~@/static/text-icon.ttf') format('truetype');
	}

	page {
		background-color: #f8f8f8;
	}

	/* #endif*/

	/* 解决头条小程序字体图标不显示问题,因为头条运行时自动插入了span标签,且有全局字体 */
	/* #ifdef MP-TOUTIAO */
	text :not(view) {
		font-family: texticons;
	}

	/* #endif */

	.center {
		flex: 1;
		flex-direction: column;
		background-color: #f8f8f8;
	}

L
213  
linju 已提交
278 279
	.userInfo {
		width: 750rpx;
280
		padding: 20rpx;
L
123  
linju 已提交
281
		padding-top: 50px;
L
213  
linju 已提交
282
		background-color: #2F85FC;
L
213  
linju 已提交
283
		flex-direction: column;
L
213  
linju 已提交
284 285 286
		align-items: center;
	}

L
123  
linju 已提交
287
	/* .logo-hover {
L
213  
linju 已提交
288
		opacity: 0.8;
L
123  
linju 已提交
289
	} */
L
213  
linju 已提交
290 291

	.logo-img {
L
213  
linju 已提交
292 293
		width: 150rpx;
		height: 150rpx;
294
		border-radius: 150rpx;
L
213  
linju 已提交
295
		border: solid 1px #FFFFFF;
L
213  
linju 已提交
296 297 298
	}

	.logo-title {
L
213  
linju 已提交
299
		height: 150rpx;
L
213  
linju 已提交
300 301 302 303
		flex: 1;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
L
213  
linju 已提交
304
		margin-left: 20rpx;
L
213  
linju 已提交
305 306 307
	}

	.uer-name {
L
213  
linju 已提交
308 309 310
		height: 60rpx;
		line-height: 60rpx;
		font-size: 38rpx;
L
213  
linju 已提交
311 312 313 314
		color: #FFFFFF;
	}

	.go-login-navigat-arrow {
L
213  
linju 已提交
315
		font-size: 38rpx;
L
213  
linju 已提交
316 317 318 319
		color: #FFFFFF;
	}

	.navigat-arrow {
L
213  
linju 已提交
320 321 322 323 324
		height: 90rpx;
		width: 40rpx;
		line-height: 90rpx;
		font-size: 34rpx;
		color: #FFFFFF;
L
213  
linju 已提交
325 326 327 328
		text-align: right;
		font-family: texticons;
	}

329
	.center-list {
L
213  
linju 已提交
330 331 332 333 334
		margin-bottom: 30rpx;
		background-color: #f9f9f9;
	}

	.center-list-cell {
335
		width: 750rpx;
L
213  
linju 已提交
336 337 338
		background-color: #007AFF;
		height: 40rpx;
	}
L
123  
linju 已提交
339 340

	.grid {
341
		background-color: #FFFFFF;
L
123  
linju 已提交
342
		margin: 25rpx 0;
L
213  
linju 已提交
343
	}
L
123  
linju 已提交
344

L
213  
linju 已提交
345 346 347 348 349 350 351 352
	.uni-grid .text {
		font-size: 26rpx;
		color: #817f82;
	}

	.uni-grid .item /deep/ .uni-grid-item__box {
		justify-content: center;
		align-items: center;
353 354
	}

L
123  
linju 已提交
355 356 357

	/*修改边线粗细示例*/
	/* #ifndef APP-NVUE */
358
	.center-list /deep/ .uni-list--border:after,
L
123  
linju 已提交
359 360
	.center-list /deep/ .uni-list--border-top,
	.center-list /deep/ .uni-list--border-bottom {
361 362 363
		-webkit-transform: scaleY(0.2);
		transform: scaleY(0.2);
	}
L
123  
linju 已提交
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385

	/* #endif */
	.item-footer {
		flex-direction: row;
		align-items: center;
	}

	.item-footer-text {
		color: #999;
		font-size: 24rpx;
		padding-right: 10rpx;
	}

	.item-footer-badge {
		width: 20rpx;
		height: 20rpx;
		/* #ifndef APP-NVUE */
		border-radius: 50%;
		/* #endif */
		/* #ifdef APP-NVUE */
		border-radius: 10rpx;
		/* #endif */
DCloud_JSON's avatar
DCloud_JSON 已提交
386
		background-color: #DD524D;
L
123  
linju 已提交
387
	}
388
</style>