|
|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
|
- <div class="page h-full flex flex-col" :style="{ backgroundImage: `url(${inPC ? pcBg : h5Bg})` }">
|
|
|
+ <div class="page h-full flex flex-col" :style="{ backgroundImage: `url(${desktopMode ? pcBg : h5Bg})` }">
|
|
|
<n-page-header>
|
|
|
<template #title>
|
|
|
<span class="title">CHILLGPT </span>
|
|
|
@@ -10,7 +10,7 @@
|
|
|
<template #extra>
|
|
|
<user-avatar avatarType="small" v-if="isLogin" />
|
|
|
<template v-else>
|
|
|
- <n-button v-if="inPC" type="primary" round @click="showLogin = true"> 登录 </n-button>
|
|
|
+ <n-button v-if="desktopMode" type="primary" round @click="showLogin = true"> 登录 </n-button>
|
|
|
<n-button v-else @click="$router.push('/login')">登录</n-button>
|
|
|
</template>
|
|
|
</template>
|
|
|
@@ -25,7 +25,7 @@
|
|
|
|
|
|
<n-card
|
|
|
class="vip"
|
|
|
- v-if="inPC"
|
|
|
+ v-if="desktopMode"
|
|
|
title="会员权益"
|
|
|
content-style="padding:0"
|
|
|
header-style="text-align:center;padding:0;height:44px;line-height:44px;font-size: 16px;font-family: AlimamaShuHeiTi;"
|
|
|
@@ -112,90 +112,45 @@
|
|
|
header-style="text-align:center;padding:30px;font-size:24px;"
|
|
|
>
|
|
|
<div class="login-box">
|
|
|
- <n-form ref="formRef" :model="form" :rules="rules" :show-label="false">
|
|
|
- <n-form-item ref="phoneRef" path="phone" label="">
|
|
|
- <n-input v-model:value="form.phone" :input-props="{ type: 'tel' }" @keydown.enter.prevent>
|
|
|
- <template #prefix>
|
|
|
- <img src="@/assets/user.png" class="input-pre" alt="" />
|
|
|
- </template>
|
|
|
- </n-input>
|
|
|
- </n-form-item>
|
|
|
- <n-form-item path="code" label="">
|
|
|
- <n-input-group>
|
|
|
- <n-input
|
|
|
- v-model:value="form.code"
|
|
|
- :input-props="{ type: 'tel' }"
|
|
|
- @input="handlePasswordInput"
|
|
|
- @keydown.enter.prevent
|
|
|
- >
|
|
|
- <template #prefix>
|
|
|
- <img src="@/assets/code.png" class="input-pre" alt="" />
|
|
|
- </template>
|
|
|
- </n-input>
|
|
|
- <n-button class="send" :disabled="isSend" type="tertiary" secondary @click.stop="send">
|
|
|
- {{ isSend ? `已发送(${sendNum}S)` : '发送验证码' }}
|
|
|
- </n-button>
|
|
|
- </n-input-group>
|
|
|
- </n-form-item>
|
|
|
-
|
|
|
- <div class="check">
|
|
|
- <n-checkbox v-model:checked="checked">
|
|
|
- 已阅读同意 <span class="prim" @click.stop="">《用户服务协议》</span>和<span
|
|
|
- class="prim"
|
|
|
- @click.stop=""
|
|
|
- >《平台隐私协》</span
|
|
|
- >
|
|
|
- </n-checkbox>
|
|
|
- </div>
|
|
|
-
|
|
|
- <div class="submit">
|
|
|
- <n-button @click="submit" block type="primary" size="large" :loading="loading" circle>
|
|
|
- 登录
|
|
|
- </n-button>
|
|
|
- </div>
|
|
|
- </n-form>
|
|
|
+ <login-form @success="onLogin"></login-form>
|
|
|
</div>
|
|
|
</n-card>
|
|
|
</n-modal>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
-<script setup>
|
|
|
-import {
|
|
|
- NForm,
|
|
|
- NFormItem,
|
|
|
- NInput,
|
|
|
- NInputGroup,
|
|
|
- NCheckbox,
|
|
|
- NAvatar,
|
|
|
- NButton,
|
|
|
- NPageHeader,
|
|
|
- NCard,
|
|
|
- useMessage,
|
|
|
- NGrid,
|
|
|
- NGridItem,
|
|
|
- NModal
|
|
|
-} from 'naive-ui'
|
|
|
+<script setup lang="ts">
|
|
|
+import { NAvatar, NButton, NPageHeader, NCard, NGrid, NGridItem, NModal } from 'naive-ui'
|
|
|
import h5Bg from '@/assets/png-shouye.jpg'
|
|
|
import pcBg from '@/assets/png-bg.jpg'
|
|
|
import logo from '@/assets/logo.png'
|
|
|
import { useUserStore } from '@/store'
|
|
|
import { useRouter } from 'vue-router'
|
|
|
import { ref, computed } from 'vue'
|
|
|
-import { http } from '@/plugins/http'
|
|
|
-import { UserAvatar } from '@/components/common'
|
|
|
+import { UserAvatar, LoginForm } from '@/components/common'
|
|
|
+import { useWindowSize } from '@vueuse/core'
|
|
|
|
|
|
-const inPC = window.innerWidth >= 1024
|
|
|
+const { width } = useWindowSize()
|
|
|
+const desktopMode = computed(() => {
|
|
|
+ return width.value > 768
|
|
|
+})
|
|
|
|
|
|
+const router = useRouter()
|
|
|
const userStore = useUserStore()
|
|
|
+const showLogin = ref(false)
|
|
|
+
|
|
|
const isLogin = computed(() => {
|
|
|
return !!userStore.userInfo.id
|
|
|
})
|
|
|
|
|
|
-const router = useRouter()
|
|
|
+const onLogin = () => {
|
|
|
+ showLogin.value = false
|
|
|
+ router.replace({ name: 'Chat' })
|
|
|
+}
|
|
|
+
|
|
|
function goChat() {
|
|
|
if (!userStore.userInfo.id) {
|
|
|
- if (inPC) {
|
|
|
+ if (desktopMode.value) {
|
|
|
showLogin.value = true
|
|
|
} else {
|
|
|
router.push('/login')
|
|
|
@@ -204,121 +159,6 @@ function goChat() {
|
|
|
router.push('/chat')
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-const showLogin = ref(false)
|
|
|
-const form = ref({
|
|
|
- phone: '',
|
|
|
- code: ''
|
|
|
-})
|
|
|
-const formRef = ref(null)
|
|
|
-const message = useMessage()
|
|
|
-function submit() {
|
|
|
- loading.value = true
|
|
|
- formRef.value
|
|
|
- .validate()
|
|
|
- .then(() => {
|
|
|
- if (checked.value) {
|
|
|
- userStore
|
|
|
- .loginByCode(form.value.phone, form.value.code)
|
|
|
- .then(() => {
|
|
|
- loading.value = false
|
|
|
- message.success('登录成功')
|
|
|
- showLogin.value = false
|
|
|
- userStore.getUserInfo()
|
|
|
- })
|
|
|
- .catch(e => {
|
|
|
- loading.value = false
|
|
|
- console.log(e)
|
|
|
- if (e && e.message) {
|
|
|
- this.message.error(e.message)
|
|
|
- setTime(0)
|
|
|
- form.value.code = ''
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- loading.value = false
|
|
|
- message.error('请先阅读并同意协议')
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(() => {
|
|
|
- loading.value = false
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-const rules = ref({
|
|
|
- phone: [
|
|
|
- {
|
|
|
- validator(rule, value) {
|
|
|
- if (!value) {
|
|
|
- return new Error('请输入手机号')
|
|
|
- } else if (!/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(value)) {
|
|
|
- return new Error('手机号格式错误')
|
|
|
- }
|
|
|
-
|
|
|
- return true
|
|
|
- },
|
|
|
- trigger: ['blur']
|
|
|
- }
|
|
|
- ],
|
|
|
- code: [
|
|
|
- {
|
|
|
- required: true,
|
|
|
- message: '请输入验证码',
|
|
|
- trigger: ['blur']
|
|
|
- }
|
|
|
- ]
|
|
|
-})
|
|
|
-const checked = ref(false)
|
|
|
-const phoneRef = ref(null)
|
|
|
-const loading = ref(false)
|
|
|
-function send() {
|
|
|
- loading.value = true
|
|
|
- phoneRef.value
|
|
|
- ?.validate()
|
|
|
- .then(errors => {
|
|
|
- isSend.value = true
|
|
|
- setTime(60)
|
|
|
- http.post(
|
|
|
- '/api/sms/sendVerify',
|
|
|
- {
|
|
|
- phone: form.value.phone
|
|
|
- },
|
|
|
- {
|
|
|
- body: 'json'
|
|
|
- }
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- loading.value = false
|
|
|
- form.value.msgCode = res
|
|
|
- })
|
|
|
- .catch(e => {
|
|
|
- loading.value = false
|
|
|
- setTime(0)
|
|
|
- })
|
|
|
- })
|
|
|
- .catch(() => {
|
|
|
- loading.value = false
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-const isSend = ref(false)
|
|
|
-const sendNum = ref(60)
|
|
|
-const timer = ref(null)
|
|
|
-function setTime(num) {
|
|
|
- sendNum.value = num
|
|
|
- if (timer.value) {
|
|
|
- clearTimeout(timer.value)
|
|
|
- }
|
|
|
-
|
|
|
- if (num <= 0) {
|
|
|
- isSend.value = false
|
|
|
- return
|
|
|
- } else {
|
|
|
- timer.value = setTimeout(() => {
|
|
|
- setTime(num - 1)
|
|
|
- }, 1000)
|
|
|
- }
|
|
|
-}
|
|
|
</script>
|
|
|
|
|
|
<style lang="less" scoped>
|