old易 2024-09-28 11:05:44 +08:00
parent f669ff4192
commit d6fd328dca
4 changed files with 42 additions and 5 deletions

View File

@ -0,0 +1 @@
VUE_APP_WECHAT_APPID=wxf8db44d5ec082dfc

View File

@ -0,0 +1 @@
VUE_APP_WECHAT_APPID=wxf8db44d5ec082dfc

View File

@ -17,13 +17,14 @@
<div v-if="selectedTab === 'phone'"> <div v-if="selectedTab === 'phone'">
<input type="text" placeholder="手机号" v-model="phone" /> <input type="text" placeholder="手机号" v-model="phone" />
<div v-if="phoneError" class="error-message">{{ phoneError }}</div> <!-- Display error message -->
<div class="verification-row"> <div class="verification-row">
<input type="text" placeholder="验证码" v-model="verificationCode" /> <input type="text" placeholder="验证码" v-model="verificationCode" />
<button @click="startCountdown" :disabled="countdown !== null"> <button @click="startCountdown" :disabled="countdown !== null || !isPhoneValid">
{{ countdown !== null ? `${countdown} 秒后重新发送` : '获取验证码' }} {{ countdown !== null ? `${countdown} 秒后重新发送` : '获取验证码' }}
</button> </button>
</div> </div>
<button @click="login"></button> <button @click="login" :disabled="countdown !== null || !isPhoneValid"></button> <!-- Disable login if countdown is active or phone is invalid -->
</div> </div>
<div v-if="selectedTab === 'wechat'"> <div v-if="selectedTab === 'wechat'">
@ -34,7 +35,7 @@
</template> </template>
<script> <script>
import { ref, onMounted, watch, nextTick } from 'vue'; import { ref, onMounted, watch, nextTick, computed } from 'vue';
export default { export default {
setup() { setup() {
@ -45,10 +46,12 @@ export default {
const phone = ref(''); const phone = ref('');
const verificationCode = ref(''); const verificationCode = ref('');
const referer = ref(''); // const referer = ref(''); //
const phoneError = ref(''); //
// //
const switchTab = (tab) => { const switchTab = (tab) => {
selectedTab.value = tab; selectedTab.value = tab;
phoneError.value = ''; // Reset error message on tab switch
}; };
// //
@ -91,7 +94,7 @@ export default {
// //
const initWeChatLogin = () => { const initWeChatLogin = () => {
nextTick(() => { nextTick(() => {
console.log(import.meta.env.VUE_APP_WECHAT_APPID);
const appid = 'wxf8db44d5ec082dfc'; const appid = 'wxf8db44d5ec082dfc';
const redirectUri = encodeURIComponent('https://api.sso.ycymedu.com/api/syswechat/snlogin?redirect_uri=' + referer); const redirectUri = encodeURIComponent('https://api.sso.ycymedu.com/api/syswechat/snlogin?redirect_uri=' + referer);
const state = Math.random().toString(36).substr(2); const state = Math.random().toString(36).substr(2);
@ -109,6 +112,22 @@ export default {
}); });
}; };
//
const isPhoneValid = computed(() => {
const phoneRegex = /^1[3-9]\d{9}$/; //
if (!phone.value) {
phoneError.value = '请输入手机号';
return false;
} else if (!phoneRegex.test(phone.value)) {
phoneError.value = '请输入有效的手机号';
return false;
}
phoneError.value = ''; //
return true;
});
// //
onMounted(() => { onMounted(() => {
getReferer(); // getReferer(); //
@ -124,6 +143,10 @@ export default {
// //
const login = () => { const login = () => {
if (selectedTab.value === 'phone' && !isPhoneValid.value) {
alert('请检查手机号'); //
return;
}
alert('登录功能尚未实现'); alert('登录功能尚未实现');
}; };
@ -137,6 +160,8 @@ export default {
switchTab, switchTab,
startCountdown, startCountdown,
login, login,
phoneError,
isPhoneValid
}; };
}, },
}; };
@ -265,5 +290,12 @@ button:disabled {
margin: 0 auto; margin: 0 auto;
/* 水平居中 */ /* 水平居中 */
} }
.error-message {
color: red;
font-size: 12px;
margin-top: -10px;
margin-bottom: 10px;
}
} }
</style> </style>

View File

@ -4,4 +4,7 @@ import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [vue()], plugins: [vue()],
build: {
target: 'esnext',
},
}) })