ucenter.vue 7.5 KB
Newer Older
L
213  
linju 已提交
1 2
<template>
	<view class="center">
L
123  
linju 已提交
3
		<view class="userInfo" @click="toSettings">
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';
L
123  
linju 已提交
33
	import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
芊里 已提交
34 35 36 37
	import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
	
	const db = uniCloud.database();
	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: [
L
123  
linju 已提交
64 65 66 67 68 69 70 71 72 73 74 75
					[
						// #ifdef APP-PLUS
						{
							title: '去评分',
							event: 'gotoMarket'
						},
						// #endif
						{
							title: '阅读过的文章',
							to: ''
						}, {
							title: '我的积分',
芊里 已提交
76 77
							to: '',
							event:'getScore'
L
123  
linju 已提交
78
						}],
L
213  
linju 已提交
79
					[{
L
123  
linju 已提交
80 81
						title: '问题与反馈',
						to: '/uni_modules/uni-feedback/pages/opendb-feedback/list' // /pages/ucenter/uni-feedback/uni-feedback uni_modules/uni-feedback/pages/opendb-feedback/list
L
213  
linju 已提交
82
					}, {
L
123  
linju 已提交
83 84 85
						title: '关于',
						to: '/pages/ucenter/about/about'
					}]
L
213  
linju 已提交
86 87 88
				]
			}
		},
芊里 已提交
89 90
		onLoad() {
			//#ifdef APP-PLUS
L
123  
linju 已提交
91 92 93 94 95 96 97
			this.ucenterList[this.ucenterList.length - 1].unshift(
				{
					title: '检查更新',
					rightText: this.appVersion.version+'-'+this.appVersion.versionCode,
					event: 'checkVersion',
					showBadge: this.appVersion.hasNew
				}
芊里 已提交
98 99
			)
			//#endif
L
123  
linju 已提交
100
		},
L
213  
linju 已提交
101 102 103 104
		computed: {
			...mapGetters({
				userInfo: 'user/info',
				login: 'user/hasLogin'
芊里 已提交
105 106 107 108 109 110
			})
			// #ifdef APP-PLUS
			,appVersion() {
				return getApp().appVersion
			}
			// #endif
L
213  
linju 已提交
111 112 113 114
		},
		methods: {
			...mapMutations({
				logout: 'user/logout'
115
			}),
L
123  
linju 已提交
116
			toSettings() {
117
				uni.navigateTo({
L
123  
linju 已提交
118
					url: "/pages/ucenter/settings/settings"
119
				})
L
123  
linju 已提交
120
			},
L
213  
linju 已提交
121 122 123 124 125 126 127 128
			/**
			 * 个人中心项目列表点击事件
			 */
			ucenterListClick(item) {
				if (!item.to && item.event) {
					this[item.event]();
				}
			},
L
123  
linju 已提交
129 130 131
			async checkVersion() {
				console.log(await callCheckVersion());
				checkUpdate()
L
213  
linju 已提交
132
			},
芊里 已提交
133
			goLogin() {
L
213  
linju 已提交
134 135 136 137 138 139 140 141 142 143 144
				if (!this.login) {
					console.log('点击前往登录');
					uni.navigateTo({
						url: '/uni_modules/uni-login-page/pages/index/index'
					});
				} else {
					console.log('点击编辑信息');
					uni.navigateTo({
						url: './edit/edit'
					})
				}
145
			},
L
123  
linju 已提交
146
			tapGrid(index) {
147
				uni.showToast({
L
123  
linju 已提交
148
					title: '你点击了,第' + (index + 1) + '',
149 150
					icon: 'none'
				});
151 152 153 154
			},
			/**
			 * 去应用市场评分
			 */
155
			gotoMarket() {
156 157 158 159
				// #ifdef APP-PLUS
				if (uni.getSystemInfoSync().platform == "ios") {
					// 这里填写appstore应用id
					let appstoreid = 'id1417078253';
L
123  
linju 已提交
160
					plus.runtime.openURL("itms-apps://" + 'itunes.apple.com/cn/app/wechat/' + appstoreid + '?mt=8');
161 162 163
				}
				if (uni.getSystemInfoSync().platform == "android") {
					var Uri = plus.android.importClass("android.net.Uri");
L
123  
linju 已提交
164 165 166 167 168
					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);
169 170
				}
				// #endif
芊里 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
			},
			/**
			 * 获取积分信息
			 */
			getScore() {
			  uni.showLoading({
			    mask: true
			  })
			  db.collection(dbCollectionName).field('score,balance').get().then((res) => {
			    const data = res.result.data[0]
				console.log(data);
			  }).catch((err) => {
			    uni.showModal({
			      content: err.message || '请求服务失败',
			      showCancel: false
			    })
			  }).finally(() => {
			    uni.hideLoading()
			  })
L
213  
linju 已提交
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
			}
		}
	}
</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 已提交
224 225
	.userInfo {
		width: 750rpx;
226
		padding: 20rpx;
L
123  
linju 已提交
227
		padding-top: 50px;
L
213  
linju 已提交
228
		background-color: #2F85FC;
L
213  
linju 已提交
229
		flex-direction: column;
L
213  
linju 已提交
230 231 232
		align-items: center;
	}

L
123  
linju 已提交
233
	/* .logo-hover {
L
213  
linju 已提交
234
		opacity: 0.8;
L
123  
linju 已提交
235
	} */
L
213  
linju 已提交
236 237

	.logo-img {
L
213  
linju 已提交
238 239
		width: 150rpx;
		height: 150rpx;
240
		border-radius: 150rpx;
L
213  
linju 已提交
241
		border: solid 1px #FFFFFF;
L
213  
linju 已提交
242 243 244
	}

	.logo-title {
L
213  
linju 已提交
245
		height: 150rpx;
L
213  
linju 已提交
246 247 248 249
		flex: 1;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
L
213  
linju 已提交
250
		margin-left: 20rpx;
L
213  
linju 已提交
251 252 253
	}

	.uer-name {
L
213  
linju 已提交
254 255 256
		height: 60rpx;
		line-height: 60rpx;
		font-size: 38rpx;
L
213  
linju 已提交
257 258 259 260
		color: #FFFFFF;
	}

	.go-login-navigat-arrow {
L
213  
linju 已提交
261
		font-size: 38rpx;
L
213  
linju 已提交
262 263 264 265
		color: #FFFFFF;
	}

	.navigat-arrow {
L
213  
linju 已提交
266 267 268 269 270
		height: 90rpx;
		width: 40rpx;
		line-height: 90rpx;
		font-size: 34rpx;
		color: #FFFFFF;
L
213  
linju 已提交
271 272 273 274
		text-align: right;
		font-family: texticons;
	}

275
	.center-list {
L
213  
linju 已提交
276 277 278 279 280
		margin-bottom: 30rpx;
		background-color: #f9f9f9;
	}

	.center-list-cell {
281
		width: 750rpx;
L
213  
linju 已提交
282 283 284
		background-color: #007AFF;
		height: 40rpx;
	}
L
123  
linju 已提交
285 286

	.grid {
287
		background-color: #FFFFFF;
L
123  
linju 已提交
288
		margin: 25rpx 0;
L
213  
linju 已提交
289
	}
L
123  
linju 已提交
290

L
213  
linju 已提交
291 292 293 294 295 296 297 298
	.uni-grid .text {
		font-size: 26rpx;
		color: #817f82;
	}

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

L
123  
linju 已提交
301 302 303

	/*修改边线粗细示例*/
	/* #ifndef APP-NVUE */
304
	.center-list /deep/ .uni-list--border:after,
L
123  
linju 已提交
305 306
	.center-list /deep/ .uni-list--border-top,
	.center-list /deep/ .uni-list--border-bottom {
307 308 309
		-webkit-transform: scaleY(0.2);
		transform: scaleY(0.2);
	}
L
123  
linju 已提交
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333

	/* #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 */
		background-color: #DD524D;
	}
L
123  
linju 已提交
334
</style>