ucenter.vue 9.5 KB
Newer Older
L
213  
linju 已提交
1 2
<template>
	<view class="center">
3
		<view class="userInfo" @click="toUserInfo">
DCloud_JSON's avatar
DCloud_JSON 已提交
4
			<image class="logo-img" :src="userInfo.avatar||avatarUrl"></image>
芊里 已提交
5
			<view class="logo-title">
6
				<text class="uer-name">{{userInfo.nickname||userInfo.username||userInfo.mobile||'未登录'}}</text>
L
213  
linju 已提交
7
			</view>
L
123  
linju 已提交
8
		</view>
9
		<uni-grid class="grid" :column="4" :showBorder="false" :square="true">
10
			<uni-grid-item class="item" v-for="(item,index) in gridList" @click.native="tapGrid(index)" :key="index">
11
				<uni-icons class="icon" color="#007AFF" :type="item.icon" size="26"></uni-icons>
芊里 已提交
12
				<text class="text">{{item.text}}</text>
L
213  
linju 已提交
13 14
			</uni-grid-item>
		</uni-grid>
15 16
		<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"
17 18
				:clickable="true" :to="item.to" @click="ucenterListClick(item)" :show-extra-icon="true"
				:extraIcon="{type:item.icon,color:'#999'}">
L
123  
linju 已提交
19 20 21 22
				<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>
DCloud_JSON's avatar
DCloud_JSON 已提交
24
		</uni-list>
L
213  
linju 已提交
25 26 27 28 29 30 31 32
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
芊里 已提交
33 34
	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';
35
	import uniShare from 'uni_modules/uni-share/js_sdk/uni-share.js';
芊里 已提交
36 37

	const db = uniCloud.database();
芊里 已提交
38
	const dbCollectionName = 'uni-id-scores';
L
213  
linju 已提交
39 40 41
	export default {
		data() {
			return {
42
				avatarUrl: '/static/uni-center/defaultAvatarUrl.png',
L
213  
linju 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
				gridList: [{
						"text": "文字1",
						"icon": "chat"
					},
					{
						"text": "文字2",
						"icon": "cloud-upload"
					},
					{
						"text": "文字3",
						"icon": "contact"
					},
					{
						"text": "文字4",
						"icon": "download"
					}
				],
				ucenterList: [
芊里 已提交
61 62 63
					[
						// #ifdef APP-PLUS
						{
64
							"title": '去评分',
65
							"event": 'gotoMarket',
66
							"icon": "hand-thumbsup"
芊里 已提交
67
						},
DCloud_JSON's avatar
DCloud_JSON 已提交
68
						//#endif
L
123  
linju 已提交
69
						{
70
							"title": '阅读过的文章',
71
							"to": '/pages/ucenter/read-news-log/read-news-log',
72
							"icon": "flag"
73
						},
DCloud_JSON's avatar
DCloud_JSON 已提交
74
						{
75 76
							"title": '我的积分',
							"to": '',
77
							"event": 'getScore',
78 79 80 81 82 83 84 85 86
							"icon": "paperplane"
						}
						// #ifndef H5
						,{
							"title": '分销推荐',
							"event": 'share',
							"icon": "redo"
						}
						// #endif
芊里 已提交
87
					],
L
213  
linju 已提交
88
					[{
89
						"title": '问题与反馈',
90
						"to": '/uni_modules/uni-feedback/pages/uni-feedback/uni-feedback',
91
						"icon": "help"
DCloud_JSON's avatar
DCloud_JSON 已提交
92
					}, {
93
						"title": '设置',
94
						"to": '/pages/ucenter/settings/settings',
95
						"icon": "gear"
96 97
					}],
					[{
98
						"title": '关于',
99
						"to": '/pages/ucenter/about/about',
100
						"icon": "info"
L
123  
linju 已提交
101
					}]
L
213  
linju 已提交
102 103 104
				]
			}
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
105
		onLoad() {
芊里 已提交
106
			//#ifdef APP-PLUS
107
			this.ucenterList[this.ucenterList.length - 2].unshift({
芊里 已提交
108 109
				title: '检查更新',
				rightText: this.appVersion.version + '-' + this.appVersion.versionCode,
110
				event: 'checkVersion',
111
				icon: 'loop',
芊里 已提交
112 113
				showBadge: this.appVersion.hasNew
			})
芊里 已提交
114
			//#endif
L
123  
linju 已提交
115
		},
L
213  
linju 已提交
116 117 118 119
		computed: {
			...mapGetters({
				userInfo: 'user/info',
				login: 'user/hasLogin'
芊里 已提交
120 121
			})
			// #ifdef APP-PLUS
122 123
			,
			appVersion() {
芊里 已提交
124 125
				return getApp().appVersion
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
126
			// #endif
127 128
			,
			appConfig() {
DCloud_JSON's avatar
DCloud_JSON 已提交
129
				return getApp().globalData.config
DCloud_JSON's avatar
DCloud_JSON 已提交
130
			}
L
213  
linju 已提交
131
		},
132 133 134
		methods: {
			...mapMutations({
				setUserInfo: 'user/login'
135
			}),
L
123  
linju 已提交
136
			toSettings() {
137
				uni.navigateTo({
L
123  
linju 已提交
138
					url: "/pages/ucenter/settings/settings"
139
				})
L
123  
linju 已提交
140
			},
L
213  
linju 已提交
141 142 143 144 145 146 147 148
			/**
			 * 个人中心项目列表点击事件
			 */
			ucenterListClick(item) {
				if (!item.to && item.event) {
					this[item.event]();
				}
			},
芊里 已提交
149
			async checkVersion() {
150 151
				let res = await callCheckVersion()
				console.log(res);
152 153 154
				if (res.result.code > 0) {
					checkUpdate()
				} else {
155 156 157 158
					uni.showToast({
						title: res.result.message,
						icon: 'none'
					});
DCloud_JSON's avatar
123  
DCloud_JSON 已提交
159
				}
L
213  
linju 已提交
160
			},
161 162
			toUserInfo() {
				uni.navigateTo({
DCloud_JSON's avatar
DCloud_JSON 已提交
163
					url: '/pages/ucenter/userinfo/userinfo'
164
				})
165
			},
L
123  
linju 已提交
166
			tapGrid(index) {
167
				uni.showToast({
L
123  
linju 已提交
168
					title: '你点击了,第' + (index + 1) + '',
169 170
					icon: 'none'
				});
171 172 173 174
			},
			/**
			 * 去应用市场评分
			 */
芊里 已提交
175
			gotoMarket() {
DCloud_JSON's avatar
DCloud_JSON 已提交
176
				// #ifdef APP-PLUS
177 178
				if (uni.getSystemInfoSync().platform == "ios") {
					// 这里填写appstore应用id
179
					let appstoreid = this.appConfig.marketId.ios; // 'id1417078253';
L
123  
linju 已提交
180
					plus.runtime.openURL("itms-apps://" + 'itunes.apple.com/cn/app/wechat/' + appstoreid + '?mt=8');
181 182 183
				}
				if (uni.getSystemInfoSync().platform == "android") {
					var Uri = plus.android.importClass("android.net.Uri");
DCloud_JSON's avatar
DCloud_JSON 已提交
184
					var uri = Uri.parse("market://details?id=" + this.appConfig.marketId.android);
L
123  
linju 已提交
185 186 187 188
					var Intent = plus.android.importClass('android.content.Intent');
					var intent = new Intent(Intent.ACTION_VIEW, uri);
					var main = plus.android.runtimeMainActivity();
					main.startActivity(intent);
189 190
				}
				// #endif
芊里 已提交
191 192 193 194 195 196 197 198 199 200 201 202
			},
			/**
			 * 获取积分信息
			 */
			getScore() {
				if (!this.userInfo) return uni.showToast({
					title: '请登录后查看积分',
					icon: 'none'
				});
				uni.showLoading({
					mask: true
				})
芊里 已提交
203
				db.collection(dbCollectionName).where('user_id == $env.uid').field('score,balance').get().then((res) => {
芊里 已提交
204
					const data = res.result.data[0];
205
					let msg = '';
芊里 已提交
206
					msg = data ? ('当前积分为' + data.balance) : '当前无积分';
芊里 已提交
207
					uni.showToast({
芊里 已提交
208
						title: msg,
芊里 已提交
209 210 211 212 213
						icon: 'none'
					});
				}).finally(() => {
					uni.hideLoading()
				})
214 215 216 217 218 219 220 221 222 223 224 225 226 227 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
			},
			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
				uniShare({
					content: { //公共的分享类型(type)、链接(herf)、标题(title)、summary(描述)、imageUrl(缩略图)
						type: 0,
						href: this.appConfig.h5.url +
							`/#/pages/ucenter/invite/invite?code=${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",
							"text": "微信好友",
							"share": {
								"provider": "weixin",
								"scene": "WXSceneSession"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/wechatmoments.png",
							"text": "微信朋友圈",
							"share": {
								"provider": "weixin",
								"scene": "WXSenceTimeline"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/weibo.png",
							"text": "微博",
							"share": {
								"provider": "sinaweibo"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/qq.png",
							"text": "QQ",
							"share": {
								"provider": "qq"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/copyurl.png",
							"text": "复制",
							"share": "copyurl"
						},
						{
							"img": "/static/app-plus/sharemenu/more.png",
							"text": "更多",
							"share": "shareSystem"
						}
					],
					cancelText: "取消分享",
				}, e => { //callback
					console.log(e);
				})
				// #endif
L
213  
linju 已提交
287 288 289 290 291 292 293 294 295 296
			}
		}
	}
</script>

<style>
	/* #ifndef APP-PLUS-NVUE */
	page {
		background-color: #f8f8f8;
	}
297

L
213  
linju 已提交
298 299 300 301 302 303 304
	/* #endif*/

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

L
213  
linju 已提交
306 307
	.userInfo {
		width: 750rpx;
308
		padding: 20rpx;
L
123  
linju 已提交
309
		padding-top: 50px;
310
		background-image: url(../../static/uni-center/headers.png);
L
213  
linju 已提交
311
		flex-direction: column;
L
213  
linju 已提交
312 313
		align-items: center;
	}
314

L
213  
linju 已提交
315
	.logo-img {
L
213  
linju 已提交
316 317
		width: 150rpx;
		height: 150rpx;
318
		border-radius: 150rpx;
L
213  
linju 已提交
319
	}
320

L
213  
linju 已提交
321 322 323 324 325 326 327 328
	.logo-title {
		flex: 1;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
	}

	.uer-name {
329 330
		height: 100rpx;
		line-height: 100rpx;
L
213  
linju 已提交
331
		font-size: 38rpx;
L
213  
linju 已提交
332 333
		color: #FFFFFF;
	}
334

335
	.center-list {
L
213  
linju 已提交
336 337 338
		margin-bottom: 30rpx;
		background-color: #f9f9f9;
	}
339

L
213  
linju 已提交
340
	.center-list-cell {
341
		width: 750rpx;
L
213  
linju 已提交
342 343 344
		background-color: #007AFF;
		height: 40rpx;
	}
345

L
123  
linju 已提交
346
	.grid {
347
		background-color: #FFFFFF;
DCloud_JSON's avatar
DCloud_JSON 已提交
348
		margin-bottom: 6px;
L
213  
linju 已提交
349
	}
L
123  
linju 已提交
350

L
213  
linju 已提交
351
	.uni-grid .text {
352
		font-size: 30rpx;
DCloud_JSON's avatar
DCloud_JSON 已提交
353 354
		height: 25px;
		line-height: 25px;
L
213  
linju 已提交
355 356 357 358 359 360
		color: #817f82;
	}

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

L
123  
linju 已提交
363 364 365

	/*修改边线粗细示例*/
	/* #ifndef APP-NVUE */
366
	.center-list /deep/ .uni-list--border:after {
367
		-webkit-transform: scaleY(0.2);
368
		transform: scaleY(0.2);
DCloud_JSON's avatar
DCloud_JSON 已提交
369
		margin-left: 80rpx;
370 371 372 373 374 375 376
	}

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

L
123  
linju 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
	/* #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 */
398
		background-color: #DD524D;
L
123  
linju 已提交
399
	}
400
</style>