ucenter.vue 10.5 KB
Newer Older
L
213  
linju 已提交
1
<template>
DCloud_JSON's avatar
DCloud_JSON 已提交
2 3
	<view class="center">
		<uni-sign-in ref="signIn"></uni-sign-in>
4
		<view class="userInfo" @click.capture="toUserInfo">
A
Admin 已提交
5
			<uni-file-picker v-if="userInfo.avatar_file&&userInfo.avatar_file.url" v-model="userInfo.avatar_file"
DCloud_JSON's avatar
DCloud_JSON 已提交
6 7
				fileMediatype="image" :del-icon="false" return-type="object" :image-styles="listStyles" disablePreview
				disabled />
8
			<image v-else class="logo-img" src="/static/uni-center/defaultAvatarUrl.png"></image>
9 10 11
			<view class="logo-title">
				<text class="uer-name" v-if="hasLogin">{{userInfo.nickname||userInfo.username||userInfo.mobile}}</text>
				<text class="uer-name" v-else>未登陆</text>
L
213  
linju 已提交
12
			</view>
L
123  
linju 已提交
13
		</view>
14
		<uni-grid class="grid" :column="4" :showBorder="false" :square="true">
15
			<uni-grid-item class="item" v-for="(item,index) in gridList" @click.native="tapGrid(index)" :key="index">
16
				<uni-icons class="icon" color="#007AFF" :type="item.icon" size="26"></uni-icons>
芊里 已提交
17
				<text class="text">{{item.text}}</text>
L
213  
linju 已提交
18 19
			</uni-grid-item>
		</uni-grid>
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"
22 23
				:clickable="true" :to="item.to" @click="ucenterListClick(item)" :show-extra-icon="true"
				:extraIcon="{type:item.icon,color:'#999'}">
L
123  
linju 已提交
24 25 26 27
				<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>
芊里 已提交
28
			</uni-list-item>
DCloud_JSON's avatar
DCloud_JSON 已提交
29
		</uni-list>
L
213  
linju 已提交
30 31 32 33 34 35 36 37
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
芊里 已提交
38 39
	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';
DCloud_JSON's avatar
DCloud_JSON 已提交
40
	import uniShare from '@/uni_modules/uni-share/js_sdk/uni-share.js';
芊里 已提交
41 42

	const db = uniCloud.database();
L
213  
linju 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
	export default {
		data() {
			return {
				gridList: [{
						"text": "文字1",
						"icon": "chat"
					},
					{
						"text": "文字2",
						"icon": "cloud-upload"
					},
					{
						"text": "文字3",
						"icon": "contact"
					},
					{
						"text": "文字4",
						"icon": "download"
					}
				],
				ucenterList: [
64
					[{
DCloud_JSON's avatar
DCloud_JSON 已提交
65 66 67
							"title": '签到有奖',
							"event": 'signIn',
							"icon": "compose"
68
						},
芊里 已提交
69 70
						// #ifdef APP-PLUS
						{
71
							"title": '去评分',
72
							"event": 'gotoMarket',
73
							"icon": "hand-thumbsup"
芊里 已提交
74
						},
DCloud_JSON's avatar
DCloud_JSON 已提交
75
						//#endif
L
123  
linju 已提交
76
						{
77
							"title": '阅读过的文章',
78
							"to": '/pages/ucenter/read-news-log/read-news-log',
79
							"icon": "flag"
80
						},
DCloud_JSON's avatar
DCloud_JSON 已提交
81
						{
82 83
							"title": '我的积分',
							"to": '',
84
							"event": 'getScore',
85
							"icon": "paperplane"
DCloud_JSON's avatar
DCloud_JSON 已提交
86 87
						}
						// #ifdef APP-PLUS
88
						, {
DCloud_JSON's avatar
DCloud_JSON 已提交
89 90 91 92
							"title": '分销推荐',
							"event": 'share',
							"icon": "redo"
						}
93
						// #endif
芊里 已提交
94
					],
L
213  
linju 已提交
95
					[{
96
						"title": '问题与反馈',
97
						"to": '/uni_modules/uni-feedback/pages/uni-feedback/uni-feedback',
98
						"icon": "help"
DCloud_JSON's avatar
DCloud_JSON 已提交
99
					}, {
100
						"title": '设置',
101
						"to": '/pages/ucenter/settings/settings',
102
						"icon": "gear"
103 104
					}],
					[{
105
						"title": '关于',
106
						"to": '/pages/ucenter/about/about',
107
						"icon": "info"
L
123  
linju 已提交
108
					}]
DCloud_JSON's avatar
DCloud_JSON 已提交
109 110 111 112 113 114 115 116 117 118
				],
				listStyles: {
					"height": "150rpx", // 边框高度
					"width": "150rpx", // 边框宽度
					"border": { // 如果为 Boolean 值,可以控制边框显示与否
						"color": "#eee", // 边框颜色
						"width": "1px", // 边框宽度
						"style": "solid", // 边框样式
						"radius": "100%" // 边框圆角,支持百分比
					}
119
				}
L
213  
linju 已提交
120 121
			}
		},
122 123
		onLoad() {
			console.log(313,this.userInfo,this.hasLogin);
芊里 已提交
124
			//#ifdef APP-PLUS
125
			this.ucenterList[this.ucenterList.length - 2].unshift({
芊里 已提交
126 127
				title: '检查更新',
				rightText: this.appVersion.version + '-' + this.appVersion.versionCode,
128
				event: 'checkVersion',
129
				icon: 'loop',
芊里 已提交
130 131
				showBadge: this.appVersion.hasNew
			})
芊里 已提交
132
			//#endif
L
123  
linju 已提交
133
		},
L
213  
linju 已提交
134 135 136
		computed: {
			...mapGetters({
				userInfo: 'user/info',
137
				hasLogin: 'user/hasLogin'
芊里 已提交
138 139
			})
			// #ifdef APP-PLUS
140 141
			,
			appVersion() {
芊里 已提交
142 143
				return getApp().appVersion
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
144
			// #endif
145 146
			,
			appConfig() {
DCloud_JSON's avatar
DCloud_JSON 已提交
147
				return getApp().globalData.config
DCloud_JSON's avatar
DCloud_JSON 已提交
148
			}
L
213  
linju 已提交
149
		},
150 151 152
		methods: {
			...mapMutations({
				setUserInfo: 'user/login'
153
			}),
L
123  
linju 已提交
154
			toSettings() {
155
				uni.navigateTo({
L
123  
linju 已提交
156
					url: "/pages/ucenter/settings/settings"
157
				})
DCloud_JSON's avatar
DCloud_JSON 已提交
158
			},
159
			signIn() { //签到
DCloud_JSON's avatar
DCloud_JSON 已提交
160
				this.$refs.signIn.open()
L
123  
linju 已提交
161
			},
L
213  
linju 已提交
162 163 164 165 166 167 168 169
			/**
			 * 个人中心项目列表点击事件
			 */
			ucenterListClick(item) {
				if (!item.to && item.event) {
					this[item.event]();
				}
			},
芊里 已提交
170
			async checkVersion() {
171 172
				let res = await callCheckVersion()
				console.log(res);
173 174 175
				if (res.result.code > 0) {
					checkUpdate()
				} else {
176 177 178 179
					uni.showToast({
						title: res.result.message,
						icon: 'none'
					});
DCloud_JSON's avatar
123  
DCloud_JSON 已提交
180
				}
L
213  
linju 已提交
181
			},
182 183
			toUserInfo() {
				uni.navigateTo({
DCloud_JSON's avatar
DCloud_JSON 已提交
184
					url: '/pages/ucenter/userinfo/userinfo'
185
				})
186
			},
L
123  
linju 已提交
187
			tapGrid(index) {
188
				uni.showToast({
L
123  
linju 已提交
189
					title: '你点击了,第' + (index + 1) + '',
190 191
					icon: 'none'
				});
192 193 194 195
			},
			/**
			 * 去应用市场评分
			 */
芊里 已提交
196
			gotoMarket() {
DCloud_JSON's avatar
DCloud_JSON 已提交
197
				// #ifdef APP-PLUS
198 199
				if (uni.getSystemInfoSync().platform == "ios") {
					// 这里填写appstore应用id
200
					let appstoreid = this.appConfig.marketId.ios; // 'id1417078253';
L
123  
linju 已提交
201
					plus.runtime.openURL("itms-apps://" + 'itunes.apple.com/cn/app/wechat/' + appstoreid + '?mt=8');
202 203 204
				}
				if (uni.getSystemInfoSync().platform == "android") {
					var Uri = plus.android.importClass("android.net.Uri");
DCloud_JSON's avatar
DCloud_JSON 已提交
205
					var uri = Uri.parse("market://details?id=" + this.appConfig.marketId.android);
L
123  
linju 已提交
206 207 208 209
					var Intent = plus.android.importClass('android.content.Intent');
					var intent = new Intent(Intent.ACTION_VIEW, uri);
					var main = plus.android.runtimeMainActivity();
					main.startActivity(intent);
210 211
				}
				// #endif
芊里 已提交
212 213 214 215 216 217 218 219 220 221 222 223
			},
			/**
			 * 获取积分信息
			 */
			getScore() {
				if (!this.userInfo) return uni.showToast({
					title: '请登录后查看积分',
					icon: 'none'
				});
				uni.showLoading({
					mask: true
				})
DCloud_JSON's avatar
DCloud_JSON 已提交
224 225
				db.collection("uni-id-scores").where('"user_id" == $env.uid').field('score,balance').get().then((res) => {
					uni.hideLoading()
226
					console.log(res);
芊里 已提交
227
					const data = res.result.data[0];
228
					let msg = '';
229
					msg = data ? ('当前积分为' + data.score) : '当前无积分';
芊里 已提交
230
					uni.showToast({
芊里 已提交
231
						title: msg,
芊里 已提交
232 233 234
						icon: 'none'
					});
				})
235 236
			},
			async share() {
237 238 239
				let {
					result
				} = await uniCloud.callFunction({
240 241 242 243
					name: 'uni-id-cf',
					data: {
						action: 'getUserInviteCode'
					}
DCloud_JSON's avatar
DCloud_JSON 已提交
244
				})
245 246 247 248 249 250 251 252
				console.log(result);
				let myInviteCode = result.myInviteCode || result.userInfo.my_invite_code
				console.log(myInviteCode);
				let {
					appName,
					logo,
					company,
					slogan
DCloud_JSON's avatar
DCloud_JSON 已提交
253 254 255 256 257 258 259 260 261
				} = 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=uniInvitationCode:${myInviteCode}`,
						title: appName,
						summary: slogan,
262 263
						imageUrl: logo +
							'?x-oss-process=image/resize,m_fill,h_100,w_100' //压缩图片解决,在ios端分享图过大导致的图片失效问题
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 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
					},
					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);
				})
310
				// #endif
L
213  
linju 已提交
311 312 313 314 315
			}
		}
	}
</script>

DCloud_JSON's avatar
DCloud_JSON 已提交
316
<style lang="scss" scoped>
317 318 319 320 321 322 323
	/* #ifndef APP-NVUE */
	view {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
	}

L
213  
linju 已提交
324 325 326
	page {
		background-color: #f8f8f8;
	}
327

L
213  
linju 已提交
328 329 330 331 332 333 334
	/* #endif*/

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

L
213  
linju 已提交
336 337
	.userInfo {
		width: 750rpx;
338
		padding: 20rpx;
L
123  
linju 已提交
339
		padding-top: 50px;
340
		background-image: url(../../static/uni-center/headers.png);
L
213  
linju 已提交
341
		flex-direction: column;
L
213  
linju 已提交
342 343
		align-items: center;
	}
344

L
213  
linju 已提交
345
	.logo-img {
L
213  
linju 已提交
346 347
		width: 150rpx;
		height: 150rpx;
348
		border-radius: 150rpx;
L
213  
linju 已提交
349
	}
350

L
213  
linju 已提交
351 352 353 354 355 356 357 358
	.logo-title {
		flex: 1;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
	}

	.uer-name {
359 360
		height: 100rpx;
		line-height: 100rpx;
L
213  
linju 已提交
361
		font-size: 38rpx;
L
213  
linju 已提交
362 363
		color: #FFFFFF;
	}
364

365
	.center-list {
L
213  
linju 已提交
366 367 368
		margin-bottom: 30rpx;
		background-color: #f9f9f9;
	}
369

L
213  
linju 已提交
370
	.center-list-cell {
371
		width: 750rpx;
L
213  
linju 已提交
372 373 374
		background-color: #007AFF;
		height: 40rpx;
	}
375

L
123  
linju 已提交
376
	.grid {
377
		background-color: #FFFFFF;
DCloud_JSON's avatar
DCloud_JSON 已提交
378
		margin-bottom: 6px;
L
213  
linju 已提交
379
	}
L
123  
linju 已提交
380

L
213  
linju 已提交
381
	.uni-grid .text {
382
		font-size: 30rpx;
DCloud_JSON's avatar
DCloud_JSON 已提交
383 384
		height: 25px;
		line-height: 25px;
L
213  
linju 已提交
385 386 387
		color: #817f82;
	}

DCloud_JSON's avatar
DCloud_JSON 已提交
388
	.uni-grid .item ::v-deep .uni-grid-item__box {
L
213  
linju 已提交
389 390
		justify-content: center;
		align-items: center;
391 392
	}

L
123  
linju 已提交
393 394 395

	/*修改边线粗细示例*/
	/* #ifndef APP-NVUE */
DCloud_JSON's avatar
DCloud_JSON 已提交
396
	.center-list ::v-deep .uni-list--border:after {
397
		-webkit-transform: scaleY(0.2);
398
		transform: scaleY(0.2);
DCloud_JSON's avatar
DCloud_JSON 已提交
399
		margin-left: 80rpx;
400 401
	}

DCloud_JSON's avatar
DCloud_JSON 已提交
402 403
	.center-list ::v-deep .uni-list--border-top,
	.center-list ::v-deep .uni-list--border-bottom {
404 405 406
		display: none;
	}

L
123  
linju 已提交
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
	/* #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 */
428
		background-color: #DD524D;
L
123  
linju 已提交
429
	}
430
</style>