ucenter.vue 11.2 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3
<template>
	<view class="center">
		<uni-sign-in ref="signIn"></uni-sign-in>
4
		<view class="userInfo" @click.capture="toUserInfo">
5 6
			<cloud-image width="150rpx" height="150rpx" v-if="userInfo.avatar_file&&userInfo.avatar_file.url" :src="userInfo.avatar_file.url"></cloud-image>
			<image v-else class="logo-img" src="@/static/uni-center/defaultAvatarUrl.png"></image>
7
			<view class="logo-title">
DCloud_JSON's avatar
DCloud_JSON 已提交
8
				<text class="uer-name" v-if="hasLogin">{{userInfo.nickname||userInfo.username||userInfo.mobile}}</text>
9
				<text class="uer-name" v-else>{{$t('mine.notLogged')}}</text>
DCloud_JSON's avatar
DCloud_JSON 已提交
10 11 12 13 14 15 16
			</view>
		</view>
		<uni-grid class="grid" :column="4" :showBorder="false" :square="true">
			<uni-grid-item class="item" v-for="(item,index) in gridList" @click.native="tapGrid(index)" :key="index">
				<uni-icons class="icon" color="#007AFF" :type="item.icon" size="26"></uni-icons>
				<text class="text">{{item.text}}</text>
			</uni-grid-item>
17
		</uni-grid>
DCloud_JSON's avatar
DCloud_JSON 已提交
18 19 20 21
		<uni-list class="center-list" v-for="(sublist , index) in ucenterList" :key="index">
			<uni-list-item v-for="(item,i) in sublist" :title="item.title" link :rightText="item.rightText" :key="i"
				:clickable="true" :to="item.to" @click="ucenterListClick(item)" :show-extra-icon="true"
				:extraIcon="{type:item.icon,color:'#999'}">
22 23 24 25 26 27
				<template v-slot:footer>
					<view v-if="item.showBadge" class="item-footer">
						<text class="item-footer-text">{{item.rightText}}</text>
						<view class="item-footer-badge"></view>
					</view>
				</template>
DCloud_JSON's avatar
DCloud_JSON 已提交
28 29 30 31 32 33 34 35 36 37 38 39
			</uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
	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';
40 41
	import UniShare from '@/uni_modules/uni-share/js_sdk/uni-share.js';
	const uniShare = new UniShare()
DCloud_JSON's avatar
DCloud_JSON 已提交
42 43
	const db = uniCloud.database();
	export default {
44 45 46 47 48 49 50 51
		onBackPress({from}) {
			if(from=='backbutton'){
				this.$nextTick(function(){
					uniShare.hide()
				})
				return uniShare.isShow;
			}
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
52 53 54
		data() {
			return {
				gridList: [{
55
						"text": this.$t('mine.showText'),
DCloud_JSON's avatar
DCloud_JSON 已提交
56 57 58
						"icon": "chat"
					},
					{
59
						"text": this.$t('mine.showText'),
DCloud_JSON's avatar
DCloud_JSON 已提交
60 61 62
						"icon": "cloud-upload"
					},
					{
63
						"text": this.$t('mine.showText'),
DCloud_JSON's avatar
DCloud_JSON 已提交
64 65 66
						"icon": "contact"
					},
					{
67
						"text": this.$t('mine.showText'),
DCloud_JSON's avatar
DCloud_JSON 已提交
68 69 70 71 72
						"icon": "download"
					}
				],
				ucenterList: [
					[{
73
							"title": this.$t('mine.signIn'),
DCloud_JSON's avatar
DCloud_JSON 已提交
74 75 76 77 78
							"event": 'signIn',
							"icon": "compose"
						},
						// #ifdef APP-PLUS
						{
79
							"title": this.$t('mine.toEvaluate'),
DCloud_JSON's avatar
DCloud_JSON 已提交
80 81 82 83 84
							"event": 'gotoMarket',
							"icon": "hand-thumbsup"
						},
						//#endif
						{
85
							"title":this.$t('mine.readArticles'),
DCloud_JSON's avatar
DCloud_JSON 已提交
86 87 88 89
							"to": '/pages/ucenter/read-news-log/read-news-log',
							"icon": "flag"
						},
						{
90
							"title": this.$t('mine.myScore'),
DCloud_JSON's avatar
DCloud_JSON 已提交
91 92 93 94 95 96
							"to": '',
							"event": 'getScore',
							"icon": "paperplane"
						}
						// #ifdef APP-PLUS
						, {
97
							"title": this.$t('mine.invite'),
DCloud_JSON's avatar
DCloud_JSON 已提交
98 99 100 101 102 103
							"event": 'share',
							"icon": "redo"
						}
						// #endif
					],
					[{
104 105 106 107 108
						"title": this.$t('mine.guestBook'),
						"to": '/pages/ucenter/guestbook/guestbook',
						"icon": "chat"
					},{
						"title": this.$t('mine.feedback'),
109
						"to": '/uni_modules/uni-feedback/pages/opendb-feedback/opendb-feedback',
DCloud_JSON's avatar
DCloud_JSON 已提交
110 111
						"icon": "help"
					}, {
112
						"title": this.$t('mine.settings'),
DCloud_JSON's avatar
DCloud_JSON 已提交
113 114 115 116
						"to": '/pages/ucenter/settings/settings',
						"icon": "gear"
					}],
					[{
117
						"title": this.$t('mine.about'),
DCloud_JSON's avatar
DCloud_JSON 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130
						"to": '/pages/ucenter/about/about',
						"icon": "info"
					}]
				],
				listStyles: {
					"height": "150rpx", // 边框高度
					"width": "150rpx", // 边框宽度
					"border": { // 如果为 Boolean 值,可以控制边框显示与否
						"color": "#eee", // 边框颜色
						"width": "1px", // 边框宽度
						"style": "solid", // 边框样式
						"radius": "100%" // 边框圆角,支持百分比
					}
131
				},
study夏羽's avatar
study夏羽 已提交
132
				uniToken:""
DCloud_JSON's avatar
DCloud_JSON 已提交
133 134
			}
		},
135 136 137
		async onLoad() {
			// const loginRes = await pwdLogin()
			// console.log(loginRes,'-------------');
study夏羽's avatar
study夏羽 已提交
138
			// this.uniToken = loginRes.token
139
			// console.log(313,this.userInfo,this.hasLogin);
DCloud_JSON's avatar
DCloud_JSON 已提交
140 141
			//#ifdef APP-PLUS
			this.ucenterList[this.ucenterList.length - 2].unshift({
142
				title:this.$t('mine.checkUpdate'),// this.this.$t('mine.checkUpdate')"检查更新"
DCloud_JSON's avatar
DCloud_JSON 已提交
143 144 145 146 147
				rightText: this.appVersion.version + '-' + this.appVersion.versionCode,
				event: 'checkVersion',
				icon: 'loop',
				showBadge: this.appVersion.hasNew
			})
148 149
			//#endif
			this.uniToken = uni.getStorageSync('uni_id_token')
study夏羽's avatar
study夏羽 已提交
150
			console.log("uniToken: ",this.uniToken);
DCloud_JSON's avatar
DCloud_JSON 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
		},
		computed: {
			...mapGetters({
				userInfo: 'user/info',
				hasLogin: 'user/hasLogin'
			})
			// #ifdef APP-PLUS
			,
			appVersion() {
				return getApp().appVersion
			}
			// #endif
			,
			appConfig() {
				return getApp().globalData.config
166
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
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
		},
		methods: {
			...mapMutations({
				setUserInfo: 'user/login'
			}),
			toSettings() {
				uni.navigateTo({
					url: "/pages/ucenter/settings/settings"
				})
			},
			signIn() { //签到
				this.$refs.signIn.open()
			},
			/**
			 * 个人中心项目列表点击事件
			 */
			ucenterListClick(item) {
				if (!item.to && item.event) {
					this[item.event]();
				}
			},
			async checkVersion() {
				let res = await callCheckVersion()
				console.log(res);
				if (res.result.code > 0) {
					checkUpdate()
				} else {
					uni.showToast({
						title: res.result.message,
						icon: 'none'
					});
				}
			},
			toUserInfo() {
				uni.navigateTo({
					url: '/pages/ucenter/userinfo/userinfo'
				})
			},
			tapGrid(index) {
				uni.showToast({
207 208
					// title: '你点击了,第' + (index + 1) + '个',
					title: this.$t('mine.clicked') + " " + (index + 1) ,
DCloud_JSON's avatar
DCloud_JSON 已提交
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
					icon: 'none'
				});
			},
			/**
			 * 去应用市场评分
			 */
			gotoMarket() {
				// #ifdef APP-PLUS
				if (uni.getSystemInfoSync().platform == "ios") {
					// 这里填写appstore应用id
					let appstoreid = this.appConfig.marketId.ios; // 'id1417078253';
					plus.runtime.openURL("itms-apps://" + 'itunes.apple.com/cn/app/wechat/' + appstoreid + '?mt=8');
				}
				if (uni.getSystemInfoSync().platform == "android") {
					var Uri = plus.android.importClass("android.net.Uri");
					var uri = Uri.parse("market://details?id=" + this.appConfig.marketId.android);
					var Intent = plus.android.importClass('android.content.Intent');
					var intent = new Intent(Intent.ACTION_VIEW, uri);
					var main = plus.android.runtimeMainActivity();
					main.startActivity(intent);
				}
				// #endif
			},
			/**
			 * 获取积分信息
			 */
235
			async getScore() {
study夏羽's avatar
study夏羽 已提交
236
				console.log("this.userInfo:------------- ",this.userInfo);
DCloud_JSON's avatar
DCloud_JSON 已提交
237
				if (!this.userInfo) return uni.showToast({
238
					title: this.$t('mine.checkScore'),
DCloud_JSON's avatar
DCloud_JSON 已提交
239 240 241 242 243
					icon: 'none'
				});
				uni.showLoading({
					mask: true
				})
study夏羽's avatar
study夏羽 已提交
244
				return await db.collection("uni-id-scores")
245 246 247 248 249 250 251 252 253 254 255 256 257
					.where('"user_id" == $env.uid')
					.field('score,balance')
					.orderBy("create_date", "desc")
					.limit(1)
					.get()
					.then((res) => {
						console.log(res);
						const data = res.result.data[0];
						let msg = '';
						msg = data ? (this.$t('mine.currentScore')+ data.balance) : this.$t('mine.noScore');
						uni.showToast({
							title: msg,
							icon: 'none'
258
						});
study夏羽's avatar
study夏羽 已提交
259 260
						return data
					}).finally((e)=>{
261
						uni.hideLoading()
study夏羽's avatar
study夏羽 已提交
262
						return e
263
					})
DCloud_JSON's avatar
DCloud_JSON 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
			},
			async share() {
				let {
					result
				} = await uniCloud.callFunction({
					name: 'uni-id-cf',
					data: {
						action: 'getUserInviteCode'
					}
				})
				console.log(result);
				let myInviteCode = result.myInviteCode || result.userInfo.my_invite_code
				console.log(myInviteCode);
				let {
					appName,
					logo,
					company,
					slogan
				} = this.appConfig.about
				// #ifdef APP-PLUS
284
				uniShare.show({
DCloud_JSON's avatar
DCloud_JSON 已提交
285 286 287 288 289 290 291 292 293 294 295
					content: { //公共的分享类型(type)、链接(herf)、标题(title)、summary(描述)、imageUrl(缩略图)
						type: 0,
						href: this.appConfig.h5.url +
							`/#/pages/ucenter/invite/invite?code=uniInvitationCode:${myInviteCode}`,
						title: appName,
						summary: slogan,
						imageUrl: logo +
							'?x-oss-process=image/resize,m_fill,h_100,w_100' //压缩图片解决,在ios端分享图过大导致的图片失效问题
					},
					menus: [{
							"img": "/static/app-plus/sharemenu/wechatfriend.png",
296
							"text": this.$t('common').wechatFriends,
DCloud_JSON's avatar
DCloud_JSON 已提交
297 298 299 300 301 302 303
							"share": {
								"provider": "weixin",
								"scene": "WXSceneSession"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/wechatmoments.png",
304
							"text": this.$t('common').wechatBbs,
DCloud_JSON's avatar
DCloud_JSON 已提交
305 306 307 308 309 310 311
							"share": {
								"provider": "weixin",
								"scene": "WXSenceTimeline"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/weibo.png",
312
							"text": this.$t('common').weibo,
DCloud_JSON's avatar
DCloud_JSON 已提交
313 314 315 316 317 318 319 320 321 322 323 324 325
							"share": {
								"provider": "sinaweibo"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/qq.png",
							"text": "QQ",
							"share": {
								"provider": "qq"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/copyurl.png",
326
							"text": this.$t('common').copy,
DCloud_JSON's avatar
DCloud_JSON 已提交
327 328 329 330
							"share": "copyurl"
						},
						{
							"img": "/static/app-plus/sharemenu/more.png",
331
							"text": this.$t('common').more,
DCloud_JSON's avatar
DCloud_JSON 已提交
332 333 334
							"share": "shareSystem"
						}
					],
335
					cancelText: this.$t('common').cancelShare,
DCloud_JSON's avatar
DCloud_JSON 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
				}, e => { //callback
					console.log(e);
				})
				// #endif
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* #ifndef APP-NVUE */
	view {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
	}

	page {
		background-color: #f8f8f8;
	}
	/* #endif*/

	.center {
		flex: 1;
360
		flex-direction: column;
DCloud_JSON's avatar
DCloud_JSON 已提交
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
		background-color: #f8f8f8;
	}

	.userInfo {
		width: 750rpx;
		padding: 20rpx;
		padding-top: 50px;
		background-image: url(../../static/uni-center/headers.png);
		flex-direction: column;
		align-items: center;
	}

	.logo-img {
		width: 150rpx;
		height: 150rpx;
		border-radius: 150rpx;
	}

	.logo-title {
		flex: 1;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
	}

	.uer-name {
		height: 100rpx;
		line-height: 100rpx;
		font-size: 38rpx;
		color: #FFFFFF;
	}

	.center-list {
		margin-bottom: 30rpx;
		background-color: #f9f9f9;
	}

	.center-list-cell {
		width: 750rpx;
		background-color: #007AFF;
		height: 40rpx;
	}

	.grid {
		background-color: #FFFFFF;
		margin-bottom: 6px;
	}

	.uni-grid .text {
		font-size: 30rpx;
		height: 25px;
		line-height: 25px;
		color: #817f82;
	}

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


	/*修改边线粗细示例*/
DCloud_JSON's avatar
DCloud_JSON 已提交
423
	/* #ifndef APP-NVUE */
DCloud_JSON's avatar
DCloud_JSON 已提交
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
	.center-list ::v-deep .uni-list--border:after {
		-webkit-transform: scaleY(0.2);
		transform: scaleY(0.2);
		margin-left: 80rpx;
	}

	.center-list ::v-deep .uni-list--border-top,
	.center-list ::v-deep .uni-list--border-bottom {
		display: none;
	}

	/* #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%;
DCloud_JSON's avatar
DCloud_JSON 已提交
452
		/* #endif */
DCloud_JSON's avatar
DCloud_JSON 已提交
453 454
		/* #ifdef APP-NVUE */
		border-radius: 10rpx;
DCloud_JSON's avatar
DCloud_JSON 已提交
455
		/* #endif */
DCloud_JSON's avatar
DCloud_JSON 已提交
456 457 458
		background-color: #DD524D;
	}
</style>