| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <template>
- <view><!-- 授权页面 --></view>
- </template>
- <script>
- export default {
- data() {
- return {
- // 获取用户信息
- ocode: '1015730314',
- // 商户appkey
- appkey: '9D6ACFE8CF9AFD07',
- // 跳转地址
- URL: 'https://chtech.ncjti.edu.cn/campusclock/app/'
- }
- },
- onLoad() {
- //检查是否存在用户信息
- this.loginFilter()
- },
- methods: {
- loginFilter() {
- const clockIn_token = uni.getStorageSync('clockIn_token')
- if (!clockIn_token) {
- let wxcode = this.getQueryString('wxcode')
- if (!wxcode) {
- window.location.href = `https://open.wecard.qq.com/connect/oauth/authorize?app_key=${this.appkey}&response_type=code&scope=snsapi_base&ocode=${
- this.ocode
- }&redirect_uri=${this.URL}&state=wxcode`
- } else {
- // 获取wxcode后请求登录
- this.login(wxcode)
- }
- } else {
- uni.reLaunch({
- url: '/pages/home/home'
- })
- }
- },
- // 用户登陆获取个人信息和token
- async login(wxcode) {
- let res = await this.$myRequest_clockIn({
- url: '/attendance/api/system/user/login/app',
- method: 'post',
- header: {
- 'content-type': 'application/json',
- platform: 2,
- 'Accept-Language': 'zh-CN,zh;q=0.9'
- },
- data: {
- redirect_uri: this.URL,
- wxcode
- }
- })
- // console.log(res)
- if (res.code == 200) {
- uni.setStorageSync('clockIn_token', res.data.token)
- uni.reLaunch({
- url: '/pages/home/home'
- })
- }
- },
- //获取当前URL指定参数
- getQueryString(name) {
- // 获取URL
- let url = window.location.href
- // 正则匹配URL
- let pattern = new RegExp('[?&]' + name + '=([^&]+)', 'i')
- let matcher = pattern.exec(url)
- if (matcher == null || matcher.length < 1) {
- return false
- }
- // 输出指定的参数值
- return decodeURIComponent(matcher[1])
- }
- }
- }
- </script>
- <style></style>
|