Commit d9bad87b authored by chenqikuai's avatar chenqikuai

commit

parent f5d2a621
......@@ -2,17 +2,33 @@
import axios, { AxiosInstance } from "axios"
const url = {
development:'http://172.16.101.135:8001',
test:'',
production:''
development: 'http://172.16.101.135:8001',
test: '',
production: ''
}
import { Toast } from "vant"
export class Service {
public service:AxiosInstance ;
constructor(){
public service: AxiosInstance;
constructor() {
this.service = axios.create({
baseURL: process.env.NODE_ENV === 'production'? url.production:url.development,
timeout: 15000
baseURL: process.env.NODE_ENV === 'production' ? url.production : url.development,
timeout: 15000,
})
const get = this.service.get
const post = this.service.post
const resolveData = (ret: any) => {
if (ret.code === 200)
return ret.data;
else {
Toast.fail(ret.message)
throw new Error(ret.message)
}
}
this.service.get = (...res) => get(...res).then(ret => resolveData(ret.data));
this.service.post = (...res) => post(...res).then(ret => resolveData(ret.data)).catch(err => {
resolveData(err.response.data)
});
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ import { PRODUCT_STATUS } from '@/constant/product'
export interface LoginDto {
codetype: string
email?:string
password:string
password?:string
telephone: string
verificationCode: string
}
......
......@@ -19,8 +19,9 @@
:value="code"
:type="codeConfig.type"
:handleChange="handleCodeChange"
:sendSms="sendSms"
:sendVoice="sendVoice"
:phone="phone"
:sendSmsFunc="sendSmsFunc"
:sendVoiceFunc="sendVoiceFunc"
:phoneValid="phoneValid"
>
</CodeInput>
......@@ -151,7 +152,7 @@ export default Vue.extend({
},
sendVoiceFunc: {
type: Function as PropType<tSendVoiceFunc>,
required: true,
required: false,
},
loginByCodeFunc: {
type: Function as PropType<tLoginByCodeFunc>,
......@@ -220,7 +221,11 @@ export default Vue.extend({
const { phone, code } = this;
// 调用注册接口
this.btnLoading = true;
const regResult = await this.registerFunc(phone, code);
try{
const regResult = await this.registerFunc(phone, code);
}catch(err){
}
this.btnLoading = false;
},
async handleClickLogin() {
......
......@@ -22,7 +22,10 @@
</div>
</template>
</Input>
<div class="mt-2 float-right text-sm text-font-blue" v-if="voiceActive">
<div
class="mt-2 float-right text-sm text-font-blue"
v-if="voiceActive && sendVoiceFunc"
>
<div
v-if="voiceCount === 60 && !voiceHasSended60Ago"
class="flex items-center"
......@@ -63,8 +66,9 @@ export default Vue.extend({
type: String,
handleChange: Function,
maxlength: Number,
sendVoice: Function,
sendSms: Function,
phone: String,
sendSmsFunc: Function,
sendVoiceFunc: Function,
phoneValid: Boolean,
sendSmsAuto: {
type: Boolean,
......@@ -93,7 +97,12 @@ export default Vue.extend({
if (!this.phoneValid) return;
if (this.smsLock === true) return;
this.smsLock = true;
await this.sendSms();
try {
await this.sendSmsFunc(this.phone);
} catch (err) {
this.smsLock = false;
return;
}
this.smsCount--;
this.timerId1 = window.setInterval(() => {
this.smsCount--;
......@@ -109,7 +118,7 @@ export default Vue.extend({
if (!this.phoneValid) return;
if (this.voiceLock === true) return;
this.voiceLock = true;
await this.sendVoice();
await this.sendVoiceFunc(this.phone);
this.voiceCount--;
this.timerId2 = window.setInterval(() => {
this.voiceCount--;
......
......@@ -8,11 +8,11 @@ export const phoneConfig = {
}
export const codeConfig = {
maxLen: 6,
maxLen: 4,
placeholder: "请输入验证码",
type: 'number',
validate(value: string) {
return value.length === 6;
return value.length === 4;
}
}
......
......@@ -4,7 +4,6 @@
title="欢迎来到乐映"
:accountStatusCheckFunc="accountStatusCheckFunc"
:sendSmsFunc="sendSmsFunc"
:sendVoiceFunc="sendVoiceFunc"
:registerFunc="registerFunc"
:loginByCodeFunc="loginByCodeFunc"
:loginByPwdFunc="loginByPwdFunc"
......@@ -29,19 +28,25 @@ export default Vue.extend({
components: { Login },
methods: {
async accountStatusCheckFunc(phone: string) {
await delay(1);
return eAccountType.REG;
const isRegisterd = await this.$service.userService.isRegisterd(phone);
if (!isRegisterd) {
return eAccountType.NO_REG;
} else {
const isPwdSet = await this.$service.userService.isPwdSet(phone);
return isPwdSet ? eAccountType.REG : eAccountType.NO_REG;
}
},
async sendSmsFunc(phone: string) {
await delay(1);
return 1;
},
async sendVoiceFunc(phone: string) {
await delay(1);
return 1;
await this.$service.userService.getVerificationCode(phone, "1");
},
async registerFunc(phone: string, code: string) {
await delay(2);
const ret = await this.$service.userService.loginAndSign({
codetype: "1",
telephone: phone,
verificationCode: code,
});
console.log(ret, "show ret");
// 如果注册成功,保存token
const success = false;
if (success) {
......
......@@ -17,8 +17,9 @@
:value="code"
:type="codeConfig.type"
:handleChange="handleCodeChange"
:sendSms="sendSms"
:sendVoice="sendVoice"
:phone="phone"
:sendSmsFunc="sendSmsFunc"
:sendVoiceFunc="sendVoiceFunc"
:phoneValid="phoneValid"
>
</CodeInput>
......
......@@ -20,8 +20,9 @@
:value="code"
:type="codeConfig.type"
:handleChange="handleCodeChange"
:sendSms="sendSms"
:sendVoice="sendVoice"
:phone="phone"
:sendSmsFunc="sendSmsFunc"
:sendVoiceFunc="sendVoiceFunc"
:phoneValid="phoneValid"
>
</CodeInput>
......
......@@ -9,8 +9,9 @@
:value="code"
:type="codeConfig.type"
:handleChange="handleCodeChange"
:sendSms="sendSms"
:sendVoice="sendVoice"
:phone="phone"
:sendSmsFunc="sendSmsFunc"
:sendVoiceFunc="sendVoiceFunc"
:phoneValid="phoneValid"
:sendSmsAuto="true"
/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment