<template>
	<view>
		<!-- 授权页面 -->
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'
import { getQueryString } from '@/utils/getParams.js'

const APPKEY = '0697FA3D7F88C96D'
const ocode = '1015730314'

// 1:校友组织
// 2:返校申请
// 3:活动
// 4:母校代言
// 5:校友相册
// 6:新闻聚焦
// 7:校友通讯录
// 8:审批管理
const pageValue = ref()

// 线上地址
const URL = 'https://chtech.ncjti.edu.cn/alumnus/alumni_api/alumni/api/login/Openid'

// 本地地址
// const URL = 'http://192.168.161.220:8687/alumni/api/login/Openid'

onLoad(() => {
	loginFilter()
})

// 获取用户token
const loginFilter = () => {
	const token = getQueryString('token')
	pageValue.value = getQueryString('urlstr')
	if (!token) {
		getCardnumberURL()
	} else {
		uni.setStorageSync('token', token)

		// 根据pageValue的值判断跳转页面
		if (pageValue.value == 1) {
			uni.reLaunch({
				url: '/pages/organization/organization'
			})
		} else if (pageValue.value == 2) {
			uni.reLaunch({
				url: '/pages/back_school/back_school'
			})
		} else if (pageValue.value == 3) {
			uni.reLaunch({
				url: '/pages/activity/activity'
			})
		} else if (pageValue.value == 4) {
			uni.reLaunch({
				url: '/pages/school_represent/school_represent'
			})
		} else if (pageValue.value == 5) {
			uni.reLaunch({
				url: '/pages/school_photo/school_photo'
			})
		} else if (pageValue.value == 6) {
			uni.reLaunch({
				url: '/pages/news/news'
			})
		} else if (pageValue.value == 7) {
			uni.reLaunch({
				url: '/pages/address_book/address_book'
			})
		} else if (pageValue.value == 8) {
			uni.reLaunch({
				url: '/pages/check/check'
			})
		} else if (pageValue.value == 9) {
			uni.reLaunch({
				url: '/pages/plan/plan'
			})
		} else {
			// uni.reLaunch({
			// 	url: '/pages/home/home'
			// })

			uni.setStorageSync('token', '')
			uni.reLaunch({
				url: '/pages/404/404?message=暂无页面'
			})
		}
	}
}

// 跳转授权页面
const getCardnumberURL = () => {
	let URL_param = URL + '?urlstr=' + pageValue.value
	window.location.href = `https://open.wecard.qq.com/connect/oauth/authorize?app_key=${APPKEY}&response_type=code&scope=snsapi_base&ocode=${ocode}&redirect_uri=${URL_param}&state=${URL_param}`
}
</script>

<style lang="scss" scoped></style>
