ソースを参照

feat(login): 登录

EvilDragon 6 ヶ月 前
コミット
944d7176f6

+ 3 - 0
env/.env.development

@@ -4,3 +4,6 @@ NODE_ENV = 'development'
 VITE_DELETE_CONSOLE = false
 # 是否开启sourcemap
 VITE_SHOW_SOURCEMAP = true
+
+# VITE_SERVER_BASEURL = 'https://www.zhuchaohui.com'
+VITE_SERVER_BASEURL = 'http://39.106.91.179:48080'

+ 4 - 1
pages.config.ts

@@ -43,6 +43,9 @@ export default defineUniPages({
   },
   condition: {
     current: -1,
-    list: [{ name: '设计游学', path: 'pages/index/study-tour/index' }],
+    list: [
+      { name: '设计游学', path: 'pages/index/study-tour/index' },
+      { name: '登录', path: 'pages/login/index' },
+    ],
   },
 })

+ 17 - 1
src/core/libs/requests.ts

@@ -1,4 +1,4 @@
-import { http, httpGet } from '@/utils/http'
+import { http, httpGet, httpPost } from '@/utils/http'
 import { Schedule } from '../models/schedule'
 import { Moment } from '../models/moment'
 import dayjs from 'dayjs'
@@ -113,5 +113,21 @@ export const getClassmate = () =>
     createdAt: dayjs('2024-07-15').toDate(),
     content: '<div>111111</div>',
   })
+export const getStudyTours = () =>
+  httpGetMock<any[]>([
+    {
+      title: '东京艺术大学设计游学',
+      createdAt: dayjs('2024-07-15').toDate(),
+      startedAt: dayjs('2024-07-15').toDate(),
+      endedAt: dayjs('2024-08-15').toDate(),
+      amount: 16000,
+    },
+  ])
+export const weixinMiniAppLogin = (phoneCode: string, loginCode: string, state: string) =>
+  httpPost<any>('/app-api/member/auth/weixin-mini-app-login', {
+    phoneCode,
+    loginCode,
+    state,
+  })
 export const httpGetMock = <T>(data: T) =>
   new Promise<IResData<T>>((resolve) => resolve({ code: 1, msg: '', data } as IResData<T>))

+ 25 - 0
src/pages.json

@@ -38,6 +38,10 @@
       {
         "name": "设计游学",
         "path": "pages/index/study-tour/index"
+      },
+      {
+        "name": "登录",
+        "path": "pages/login/index"
       }
     ]
   },
@@ -59,6 +63,10 @@
       }
     },
     {
+      "path": "pages/login/index",
+      "type": "page"
+    },
+    {
       "path": "pages/material/index",
       "type": "page",
       "style": {
@@ -143,12 +151,29 @@
       }
     },
     {
+      "path": "pages/home/study-tour/detail",
+      "type": "page",
+      "style": {
+        "navigationBarTitleText": "游学计划",
+        "navigationBarBackgroundColor": "#fff",
+        "navigationStyle": "custom"
+      }
+    },
+    {
       "path": "pages/home/study-tour/index",
       "type": "page",
       "style": {
         "navigationBarTitleText": "设计游学",
         "navigationBarBackgroundColor": "#fff"
       }
+    },
+    {
+      "path": "pages/home/study-tour/list",
+      "type": "page",
+      "style": {
+        "navigationBarTitleText": "游学计划",
+        "navigationBarBackgroundColor": "#fff"
+      }
     }
   ],
   "subPackages": []

+ 115 - 0
src/pages/login/index.vue

@@ -0,0 +1,115 @@
+<script lang="ts" setup>
+import { weixinMiniAppLogin } from '@/core/libs/requests'
+
+const loginCode = ref('')
+const phoneCode = ref('')
+const loginType = ref('weixin')
+const loginTypeOption = ref([
+  {
+    value: 'weixin',
+    text: '微信',
+  },
+  {
+    value: 'univerify',
+    text: '一键登录',
+  },
+  {
+    value: 'username',
+    text: '账号密码',
+  },
+  {
+    value: 'smsCode',
+    text: '手机验证码',
+  },
+])
+const toLogin = () => {
+  if (loginType.value === 'username') {
+    uni.navigateTo({
+      url: '/uni_modules/uni-id-pages/pages/login/login-withpwd',
+    })
+  } else {
+    uni.navigateTo({
+      url: '/pages/login/login-withoutpwd?type=' + loginType.value,
+      animationType: 'none',
+      animationDuration: 0,
+    })
+  }
+}
+const toUserInfoPage = () => {
+  uni.navigateTo({
+    url: '/uni_modules/uni-id-pages/pages/userinfo/userinfo?showLoginManage=true',
+  })
+}
+const weixinLogin = async () => {
+  //   wx.getPhoneNumber
+}
+const getPhoneNumber = async ({ detail }) => {
+  console.log(phoneCode)
+  phoneCode.value = detail.code
+  const { code } = await uni.login()
+  loginCode.value = code
+  console.log(code)
+  const a = await weixinMiniAppLogin(phoneCode.value, code, '9b2ffbc1-7425-4155-9894-9d5c08541d62')
+  console.log(a)
+}
+const getTestCode = async ({ detail }) => {
+  phoneCode.value = detail.code
+  const { code } = await uni.login()
+  loginCode.value = code
+}
+</script>
+<template>
+  <view class="content">
+    <textarea v-model="loginCode" placeholder="" placeholder-class="textarea-placeholder" />
+    <textarea v-model="phoneCode" placeholder="" placeholder-class="textarea-placeholder" />
+    <button style="margin: 20px 0 20px 0" @click="toUserInfoPage">个人资料</button>
+    <uni-forms-item label="切换登录方式" labelWidth="70">
+      <uni-data-checkbox
+        :multiple="false"
+        v-model="loginType"
+        :localdata="loginTypeOption"
+        mode="button"
+      ></uni-data-checkbox>
+    </uni-forms-item>
+    <button @click="weixinLogin">前往登录</button>
+    <!-- #ifdef MP-WEIXIN -->
+    <button type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
+      手机号一键登录
+    </button>
+    <!-- #endif -->
+    <!-- #ifdef MP-WEIXIN -->
+    <button type="primary" open-type="getPhoneNumber" @getphonenumber="getTestCode">
+      获取测试码
+    </button>
+    <!-- #endif -->
+  </view>
+</template>
+
+<style lang="scss">
+.content {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+  padding: 6rpx;
+}
+
+.logo {
+  width: 200rpx;
+  height: 200rpx;
+  margin-top: 200rpx;
+  margin-right: auto;
+  margin-bottom: 50rpx;
+  margin-left: auto;
+}
+
+.text-area {
+  display: flex;
+  justify-content: center;
+}
+
+.title {
+  font-size: 18px;
+  color: #8f8f94;
+}
+</style>

+ 4 - 1
src/types/uni-pages.d.ts

@@ -6,6 +6,7 @@
 interface NavigateToOptions {
   url: "/pages/home/index" |
        "/pages/about/about" |
+       "/pages/login/index" |
        "/pages/material/index" |
        "/pages/messages/index" |
        "/pages/mine/index" |
@@ -17,7 +18,9 @@ interface NavigateToOptions {
        "/pages/home/offline-activity/index" |
        "/pages/home/schedule/index" |
        "/pages/home/spread/index" |
-       "/pages/home/study-tour/index";
+       "/pages/home/study-tour/detail" |
+       "/pages/home/study-tour/index" |
+       "/pages/home/study-tour/list";
 }
 interface RedirectToOptions extends NavigateToOptions {}
 

+ 4 - 0
src/utils/http.ts

@@ -1,10 +1,14 @@
 import { CustomRequestOptions } from '@/interceptors/request'
 
+const header = {
+  'tenant-id': 1,
+}
 export const http = <T>(options: CustomRequestOptions) => {
   // 1. 返回 Promise 对象
   return new Promise<IResData<T>>((resolve, reject) => {
     uni.request({
       ...options,
+      header,
       dataType: 'json',
       // #ifndef MP-WEIXIN
       responseType: 'json',