lhl 2 years ago
parent
commit
f1582ef913

+ 1 - 1
App.vue

@@ -24,7 +24,7 @@ export default {
 		// 加载缓存中的用户信息
 		let userInfo = uni.getStorageSync('userInfo') || '';
 		// 判断是否拥有用户信息
-		if (userInfo.uid) {
+		if (userInfo.id) {
 			//更新登陆状态
 			uni.getStorage({
 				key: 'userInfo',

+ 16 - 1
api/login.js

@@ -67,7 +67,7 @@ export function bangding(data) {
 export function gologin(data) {
 	return request({
 		url: '/api/Login/loginsubmit',
-		method: 'POST',
+		method: 'get',
 		data
 	})
 }
@@ -102,4 +102,19 @@ export function resetpwd(data) {
 		method: 'post',
 		data
 	})
+}
+
+export function getUser(data) {
+	return request({
+		url: '/api/user/userinfo',
+		method: 'get',
+		data
+	})
+}
+export function loginout(data) {
+	return request({
+		url: '/api/Login/loginout',
+		method: 'get',
+		data
+	})
 }

+ 10 - 2
pages.json

@@ -3,7 +3,8 @@
 			"path": "pages/index/index",
 			"style": {
 				"enablePullDownRefresh": true,
-				"navigationBarTitleText": "首页"
+				"navigationBarTitleText": "首页",
+				"navigationStyle": "custom"
 			}
 		},
 		{
@@ -21,7 +22,8 @@
 		{
 			"path": "pages/transaction/cbdetail",
 			"style": {
-				"navigationBarTitleText": "充幣詳情"
+				"navigationBarTitleText": "充幣詳情",
+				"navigationStyle": "custom"
 			}
 		},
 		{
@@ -76,6 +78,12 @@
 			"style": {
 				"navigationBarTitleText": "資產"
 			}
+		},
+		{
+			"path": "pages/user/menu",
+			"style": {
+				"navigationBarTitleText": ""
+			}
 		}
 	],
 	"globalStyle": {

+ 97 - 64
pages/index/index.vue

@@ -1,5 +1,9 @@
 <template>
 	<view class="container">
+		<view class="flex" style="justify-content: space-between;padding: 20rpx 30rpx;">
+			<image src="../../static/icon/user.png" mode="" style="width: 53rpx;height: 53rpx;" @click="navto('/pages/user/menu')"></image>
+			<!-- <image src="../../static/icon/tz.png" mode="" style="width: 53rpx;height: 53rpx;"></image> -->
+		</view>
 		<!-- 轮播图 start -->
 		<swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
 			<swiper-item v-for="(item, index) in 2" :key="index" class="carousel-item" @click="bannerNavToUrl(item)">
@@ -36,34 +40,43 @@
 					<view class="btm-item-name">
 						BTC/USDT
 					</view>
-					<view class="btm-item-val">
-						15716.53
-					</view>
-					<view class="btm-item-bl">
-						-2.44%
-					</view>
+					<template v-if="listOBj['BTC-USDT']">
+						<view class="btm-item-val" :style="{'color': listOBj['BTC-USDT'].dcf > 0 ? '#5ec886': '#DD3745'}">
+							{{listOBj['BTC-USDT'].last|| '--,--'}}
+						</view>
+						<view class="btm-item-bl" :style="{'color': listOBj['BTC-USDT'].dcf > 0 ? '#5ec886': '#DD3745'}">
+							{{listOBj['BTC-USDT'].dcf || '--,--'}}%
+						</view>
+					</template>
+					
 				</view>
 				<view class="btm-item">
 					<view class="btm-item-name">
-						BTC/USDT
-					</view>
-					<view class="btm-item-val">
-						15716.53
-					</view>
-					<view class="btm-item-bl">
-						-2.44%
+						BCH/USDT
 					</view>
+					<template v-if="listOBj['BCH-USDT']">
+						<view class="btm-item-val" :style="{'color': listOBj['BCH-USDT'].dcf > 0 ? '#5ec886': '#DD3745'}" >
+							{{listOBj['BCH-USDT'].last || '--,--'}}
+						</view>
+						<view class="btm-item-bl" :style="{'color': listOBj['BCH-USDT'].dcf > 0 ? '#5ec886': '#DD3745'}">
+							{{listOBj['BCH-USDT'].dcf || '--,--'}}%
+						</view>
+					</template>
+					
 				</view>
 				<view class="btm-item">
 					<view class="btm-item-name">
 						ETH/USDT
 					</view>
-					<view class="btm-item-val">
-						15716.53
-					</view>
-					<view class="btm-item-bl">
-						-2.44%
-					</view>
+					<template v-if="listOBj['ETH-USDT']">
+						<view class="btm-item-val" :style="{'color': listOBj['ETH-USDT'].dcf > 0 ? '#5ec886': '#DD3745'}">
+							{{listOBj['ETH-USDT'].last || '--,--'}}
+						</view>
+						<view class="btm-item-bl" :style="{'color': listOBj['ETH-USDT'].dcf > 0 ? '#5ec886': '#DD3745'}">
+							{{listOBj['ETH-USDT'].dcf || '--,--'}}%
+						</view>
+					</template>
+					
 				</view>
 			</view>
 		</view>
@@ -75,20 +88,23 @@
 				<view class="title-center">最新價格</view>
 				<view class="title-right">24h漲跌</view>
 			</view>
-			<!-- <scroll-view class="swiper-box" scroll-y="true" :style="{ height: maxheight }">
-				<view class="list-main flex">
-					<view class="main-left">{{   }}</view>
-					<view class="main-center" :class="{ down: item.zd < 0, ping: item.zd == 0 }">{{ item.price == 0 ? '--.--' : item.price }}</view>
-					<view class="main-right">
-						<view class="btn" :class="{ down: item.zd < 0, ping: item.zd == 0 }">{{ item.zd }}%</view>
-					</view>
+			<view class="list-main flex" v-for="(item,index ) in listOBj">
+				<view class="main-left">{{index}}</view>
+				<view class="main-center" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">
+					{{ item.last == 0 ? '--.--' : item.last }}</view>
+				<view class="main-right">
+					<view class="btn" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">{{ item.dcf }}%</view>
 				</view>
-			</scroll-view> -->
+			</view>
 		</view>
 	</view>
 </template>
 
 <script>
+	import {
+		mapState,
+		mapMutations
+	} from 'vuex';
 	import {
 		scoketNew,
 		scoketOpen
@@ -99,35 +115,19 @@
 	export default {
 		data() {
 			return {
-				maxheight: '',
+
 				scoket: '',
 				instId: 'IOTA-USDT', //请求的产品id
-				spList:[],//需要查询的列表
-				listOBj:{}//保存实际列表对象
+				spList: [], //需要查询的列表
+				listOBj: {} //保存实际列表对象
 			};
 		},
 		computed: {
-
+			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
 		},
 		onLoad: function(option) {
-			
 
-		},
-		onReady(res) {
-			var _this = this;
-			uni.getSystemInfo({
-				success: resu => {
-					const query = uni.createSelectorQuery();
-					query.select('.swiper-box').boundingClientRect();
-					query.exec(function(res) {
-						_this.maxheight = resu.windowHeight - res[0].top + 'px';
-						console.log('打印页面的剩余高度', _this.maxheight);
-					});
-				},
-				fail: res => {
-					console.log('打印页面的剩余高度', res);
-				}
-			});
+
 		},
 		onShow: function() {
 			this.geLevertade()
@@ -140,18 +140,31 @@
 
 		},
 		methods: {
-			swiperChange(){
-				
+			navto(url) {
+				console.log(url);
+				if (!this.hasLogin) {
+					// 保存地址
+					saveUrl();
+					// 登录拦截
+					interceptor();
+				} else {
+					uni.navigateTo({
+						url
+					});
+				}
+			},
+			swiperChange() {
+
 			},
 			// 开始请求长连接
-			onScoket(){
+			onScoket() {
 				const that = this;
 				that.scoket = scoketNew("wss://wsaws.okx.com:8443/ws/v5/public");
 				that.scoket.scoketOpen().then((res) => {
-					const requestList=that.spList.map((e)=>{
-						return{
+					const requestList = that.spList.map((e) => {
+						return {
 							"channel": "tickers",
-							"instId": e.coinname.toUpperCase()+"-USDT"
+							"instId": e.coinname.toUpperCase() + "-USDT"
 						}
 					})
 					that.scoket.scoketSend({
@@ -160,27 +173,33 @@
 					}).then((res) => {
 						console.log(res, '发送成功');
 					})
-					that.scoket.scoketMessage((res)=>{
-						try{
-						that.listOBj[res.arg.instId] = res.data
-						console.log(that.listOBj,'that.listOBj++++++')
-						}catch(e){
-							console.log(res,'报错');
+					that.scoket.scoketMessage((res) => {
+						try {
+							if (res.data) {
+								// res.res.data[0].name = res.arg.instId
+								that.listOBj[res.arg.instId] = res.data[0];
+								that.listOBj[res.arg.instId].dcf = ((res.data[0].last*1 -  res.data[0].sodUtc0*1)/(res.data[0].sodUtc0*1) * 100 ).toFixed(2)
+								that.listOBj = Object.assign( {},that.listOBj);
+							}
+							console.log(that.listOBj, 'that.listOBj++++++')
+						} catch (e) {
+
+							console.log(res, res.data, '报错');
 						}
 					})
 				})
 			},
-			closeScoket(){
+			closeScoket() {
 				that.scoket.scoketClose();
 			},
 			// 获取查询列表
-			geLevertade(){
+			geLevertade() {
 				const that = this;
-				geLevertade().then((e)=>{
+				geLevertade().then((e) => {
 					that.spList = e.list;
 					// 开启长连接
 					that.onScoket()
-					
+
 				})
 			},
 			// 轮播图跳转
@@ -274,32 +293,39 @@
 			}
 		}
 	}
+
 	.list {
 		background: #ffffff;
 		border-top-left-radius: 26rpx;
 		border-top-right-radius: 26rpx;
 		padding: 40rpx 15rpx 0;
+
 		.list-title {
 			font-size: 28rpx;
 			font-family: PingFang SC;
 			font-weight: 500;
 			color: #525c6e;
 			padding-bottom: 32rpx;
+
 			.title-left {
 				text-align: left;
 				width: 33%;
 			}
+
 			.title-center {
 				text-align: center;
 				width: 33%;
 			}
+
 			.title-right {
 				text-align: right;
 				width: 33%;
 			}
 		}
+
 		.list-main {
 			padding: 12rpx 0;
+
 			.main-left {
 				text-align: left;
 				width: 33%;
@@ -308,6 +334,7 @@
 				font-weight: 500;
 				color: #525c6e;
 			}
+
 			.main-center {
 				text-align: center;
 				width: 33%;
@@ -315,18 +342,22 @@
 				font-family: PingFang SC;
 				font-weight: 500;
 				color: #e15560;
+
 				&.down {
 					color: #5ec886;
 				}
+
 				&.ping {
 					color: #525c6e;
 				}
 			}
+
 			.main-right {
 				text-align: right;
 				width: 33%;
 				display: flex;
 				justify-content: flex-end;
+
 				.btn {
 					width: 122rpx;
 					height: 63rpx;
@@ -338,9 +369,11 @@
 					font-family: PingFang SC;
 					font-weight: 500;
 					color: #ffffff;
+
 					&.down {
 						background: #5ec886;
 					}
+
 					&.ping {
 						background: #f6f6f6;
 					}

+ 21 - 1
pages/public/login.vue

@@ -25,9 +25,11 @@
 </template>
 
 <script>
+	import { mapMutations,mapState } from 'vuex';
 	import {
 		loginWx,
-		gologin
+		gologin,
+		getUser
 	} from '@/api/login.js';
 	export default {
 		data() {
@@ -40,6 +42,7 @@
 			
 		},
 		methods: {
+			...mapMutations('user',['login','setUserInfo']),
 			zc() {
 				uni.navigateTo({
 					url: '/pages/public/register',
@@ -65,6 +68,23 @@
 				}).then(res => {
 					console.log(res)
 					obj.loadingType = 'no'
+					uni.showToast({
+						title: '登錄成功',
+						duration: 2000,
+						position: 'top'
+					});
+					getUser().then(re => {
+						obj.login()
+						obj.setUserInfo(re.data)
+						setTimeout(()=> {
+							uni.switchTab({
+								url:'/pages/index/index'
+							})
+						},1500)
+					})
+					
+					
+					
 				}).catch(err => {
 					console.log(err)
 					obj.loadingType = 'no'

+ 97 - 32
pages/transaction/transaction.vue

@@ -10,19 +10,28 @@
 				<view class="title-right">24h漲跌</view>
 			</view>
 			<scroll-view class="swiper-box" scroll-y="true" :style="{ height: maxheight }">
-				<view class="list-main flex" v-for="(item, index) in list">
-					<view class="main-left">{{ item.jyd }}</view>
-					<view class="main-center" :class="{ down: item.zd < 0, ping: item.zd == 0 }">{{ item.price == 0 ? '--.--' : item.price }}</view>
-					<view class="main-right">
-						<view class="btn" :class="{ down: item.zd < 0, ping: item.zd == 0 }">{{ item.zd }}%</view>
-					</view>
+				<view class="list-main flex" v-for="(item,index ) in listOBj">
+					<view class="main-left">{{index}}</view>
+					<view class="main-center" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">
+						{{ item.last == 0 ? '--.--' : item.last }}</view>
+					<view class="main-right">
+						<view class="btn" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">{{ item.dcf }}%</view>
+					</view>
 				</view>
 			</scroll-view>
 		</view>
 	</view>
 </template>
 
-<script>
+<script>
+	import { mapMutations,mapState } from 'vuex';
+	import {
+		scoketNew,
+		scoketOpen
+	} from '@/utils/socket.js';
+	import {
+		geLevertade
+	} from '@/api/index.js';
 export default {
 	onReady(res) {
 		var _this = this;
@@ -39,40 +48,96 @@ export default {
 				console.log('打印页面的剩余高度', res);
 			}
 		});
+	},
+	computed: {
+		...mapState('user',['hasLogin'])
 	},
 	data() {
 		return {
-			typelist: [{ name: 'USDT市场' }, { name: 'LP市场' }, { name: 'BNB市场' }, { name: 'TP市场' }],
+			typelist: [{ name: 'USDT市场' }],
 			tabCurrentIndex: 0,
-			maxheight: '',
-			list: [
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'ETH/USDT', price: '0.8431', zd: -1.2 },
-				{ jyd: 'EOS/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'DOGE/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'BCH/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'BTC/USDT', price: '0', zd: 0 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: -1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: -1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: -1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: -1.2 },
-				{ jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 }
-			]
+			maxheight: '',
+			scoket: '',
+			instId: 'IOTA-USDT', //请求的产品id
+			spList: [], //需要查询的列表
+			listOBj: {} //保存实际列表对象
 		};
 	},
-	onLoad() {},
-	onShow() {},
+	onLoad() {
+		
+	},
+	onShow() {
+		if(this.hasLogin) {
+			this.geLevertade()
+		}else {
+			uni.showModal({
+				title: '提示',
+				content: '您未登錄,是否馬上登錄?',
+				complete(res) {
+					console.log(res)
+					if(res.confirm) {
+						uni.navigateTo({
+							url:'/pages/public/login'
+						})
+					}
+				}
+			})
+		}
+		
+	},
+	onHide() {
+		this.closeScoket()
+	},
 	methods: {
 		tabClick(opt) {
 			this.tabCurrentIndex = opt;
-		}
+		},
+		// 开始请求长连接
+		onScoket() {
+			const that = this;
+			that.scoket = scoketNew("wss://wsaws.okx.com:8443/ws/v5/public");
+			that.scoket.scoketOpen().then((res) => {
+				const requestList = that.spList.map((e) => {
+					return {
+						"channel": "tickers",
+						"instId": e.coinname.toUpperCase() + "-USDT"
+					}
+				})
+				that.scoket.scoketSend({
+					"op": "subscribe",
+					"args": requestList
+				}).then((res) => {
+					console.log(res, '发送成功');
+				})
+				that.scoket.scoketMessage((res) => {
+					try {
+						if (res.data) {
+							// res.res.data[0].name = res.arg.instId
+							that.listOBj[res.arg.instId] = res.data[0];
+							that.listOBj[res.arg.instId].dcf = ((res.data[0].last*1 -  res.data[0].sodUtc0*1)/(res.data[0].sodUtc0*1) * 100 ).toFixed(2)
+							that.listOBj = Object.assign( {},that.listOBj);
+						}
+						console.log(that.listOBj, 'that.listOBj++++++')
+					} catch (e) {
+		
+						console.log(res, res.data, '报错');
+					}
+				})
+			})
+		},
+		closeScoket() {
+			that.scoket.scoketClose();
+		},
+		// 获取查询列表
+		geLevertade() {
+			const that = this;
+			geLevertade().then((e) => {
+				that.spList = e.list;
+				// 开启长连接
+				that.onScoket()
+		
+			})
+		},
 	}
 };
 </script>

+ 197 - 0
pages/user/menu.vue

@@ -0,0 +1,197 @@
+<template>
+	<view class="content">
+		<view class="" style="height: 40rpx;">
+
+		</view>
+		<view class="user-wrap flex">
+			<view class="user-name">
+				{{userInfo.username}}
+			</view>
+			<view class="user-invit">
+				邀請碼:{{userInfo.invit}}
+			</view>
+		</view>
+		<!-- <view class="user-list flex">
+			<image src="../../static/icon/mu1.png" mode="" class="left-img"></image>
+			<view class="">
+				語言
+			</view>
+			<image src="../../static/icon/back.png" mode="" class="right-img"></image>
+		</view> -->
+		<view class="user-list flex">
+			<image src="../../static/icon/mu2.png" mode="" class="left-img"></image>
+			<view class="">
+				幫助中心
+			</view>
+			<image src="../../static/icon/back.png" mode="" class="right-img"></image>
+		</view>
+		<view class="user-list flex">
+			<image src="../../static/icon/mu3.png" mode="" class="left-img"></image>
+			<view class="">
+				通知
+			</view>
+			<image src="../../static/icon/back.png" mode="" class="right-img"></image>
+		</view>
+		<view class="user-list flex">
+			<image src="../../static/icon/mu4.png" mode="" class="left-img"></image>
+			<view class="">
+				修改密碼
+			</view>
+			<image src="../../static/icon/back.png" mode="" class="right-img"></image>
+		</view>
+		<view class="user-list flex">
+			<image src="../../static/icon/mu5.png" mode="" class="left-img"></image>
+			<view class="">
+				提幣地址
+			</view>
+			<image src="../../static/icon/back.png" mode="" class="right-img"></image>
+		</view>
+		<view class="user-list flex">
+			<image src="../../static/icon/mu6.png" mode="" class="left-img"></image>
+			<view class="">
+				實名認證
+			</view>
+			<image src="../../static/icon/back.png" mode="" class="right-img"></image>
+		</view>
+		<view class="loginout" @click="cancel()">
+			退出
+		</view>
+	</view>
+</template>
+
+<script>
+	import {
+		mapMutations,
+		mapState
+	} from 'vuex';
+	import {
+		getUser,
+		loginout
+	} from '@/api/login.js'
+
+	export default {
+		data() {
+			return {
+
+			}
+		},
+		computed: {
+			...mapState('user', ['userInfo'])
+		},
+		onLoad() {
+
+		},
+		onShow() {
+			this.getUser()
+		},
+		onReachBottom() {
+
+		},
+		onReady() {
+
+		},
+		methods: {
+			...mapMutations('user', ['login', 'setUserInfo', 'logout']),
+			getUser() {
+				let obj = this
+				getUser().then(res => {
+					console.log(res)
+					obj.setUserInfo(res.data)
+				})
+			},
+			cancel() {
+				// this.$refs.popup.open();
+				let obj = this;
+				uni.showModal({
+					content: '确定要退出登录么',
+					success: e => {
+						if (e.confirm) {
+							loginout().then(res => {
+								obj.logout();
+								uni.switchTab({
+									url: '/pages/index/index'
+								})
+							})
+
+
+						}
+					}
+				});
+			},
+		}
+	}
+</script>
+
+<style lang="scss">
+	page {
+		background-color: #fff;
+		height: 100%;
+	}
+
+	.user-wrap {
+		width: 674rpx;
+		height: 147rpx;
+		margin: auto;
+		background: #F9F9F9;
+		border-radius: 10rpx;
+		flex-direction: column;
+		padding-left: 27rpx;
+		justify-content: center;
+		align-items: start;
+		text-align: left;
+
+		.user-name {
+			font-size: 34rpx;
+			font-weight: 500;
+			color: #636572;
+		}
+
+		.user-invit {
+			padding: 20rpx 0;
+			font-size: 22rpx;
+			font-weight: 500;
+			color: #636572;
+		}
+	}
+
+	.user-list {
+		width: 691rpx;
+		height: 104rpx;
+		background: #FFFFFF;
+		// box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06)
+		border-radius: 28rpx;
+		margin: 20rpx auto;
+		// padding: 0 25rpx;
+
+		.left-img {
+			width: 50rpx;
+			height: 50rpx;
+		}
+
+		view {
+			padding-left: 20rpx;
+			flex-grow: 1;
+			font-size: 29rpx;
+			font-weight: bold;
+			color: #5D5D5D;
+		}
+
+		.right-img {
+			width: 50rpx;
+			height: 50rpx;
+		}
+	}
+
+	.loginout {
+		width: 675rpx;
+		height: 70rpx;
+		line-height: 70rpx;
+		text-align: center;
+		font-size: 26rpx;
+		color: #000;
+		background-color: #f4d03c;
+		margin: 50rpx auto;
+		border-radius: 20rpx;
+		font-weight: bold;
+	}
+</style>

BIN
static/icon/back.png


BIN
static/icon/mu1.png


BIN
static/icon/mu2.png


BIN
static/icon/mu3.png


BIN
static/icon/mu4.png


BIN
static/icon/mu5.png


BIN
static/icon/mu6.png


BIN
static/icon/tz.png


BIN
static/icon/user.png