|
@@ -50,6 +50,38 @@
|
|
|
</el-form>
|
|
</el-form>
|
|
|
</div>
|
|
</div>
|
|
|
</el-tab-pane>
|
|
</el-tab-pane>
|
|
|
|
|
+ <el-tab-pane label="手机号绑定">
|
|
|
|
|
+ <div class="form-wrapper">
|
|
|
|
|
+ <el-form
|
|
|
|
|
+ ref="ruleFormRef3"
|
|
|
|
|
+ :model="ruleForm3"
|
|
|
|
|
+ :rules="rules3"
|
|
|
|
|
+ label-width="140px"
|
|
|
|
|
+ class="demo-ruleForm"
|
|
|
|
|
+ status-icon
|
|
|
|
|
+ >
|
|
|
|
|
+ <el-form-item label="手机号:" prop="mobile">
|
|
|
|
|
+ <el-input type="text" :disabled="!!user.profile.mobile" v-model="ruleForm3.mobile" placeholder="请输入手机号" />
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ <el-form-item label="验证码:" prop="captcha">
|
|
|
|
|
+ <el-input type="text" :disabled="ruleForm3.mobile.length !== 11" v-model="ruleForm3.captcha" placeholder="请输入验证码" >
|
|
|
|
|
+ <template #append>
|
|
|
|
|
+ <el-button v-if="!!user.profile.mobile" @click="getCaptcha" style="width: 100px;" :disabled ="!can_send">{{smsMessage}}</el-button>
|
|
|
|
|
+ <el-button v-else @click="getCaptcha2" style="width: 100px;" :disabled ="!can_send">{{smsMessage}}</el-button>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-input>
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ <el-form-item >
|
|
|
|
|
+ <el-button v-if="!!user.profile.mobile" type="primary" color="#ed8c0f" style="color: #fff;" size="large" @click="submitForm3(ruleFormRef3)">
|
|
|
|
|
+ 解绑
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ <el-button v-else type="primary" color="#ed8c0f" style="color: #fff;" size="large" @click="submitForm4(ruleFormRef3)">
|
|
|
|
|
+ 绑定
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ </el-form>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </el-tab-pane>
|
|
|
</el-tabs>
|
|
</el-tabs>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -57,13 +89,15 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
-import { ref, reactive, onMounted, computed, inject } from 'vue'
|
|
|
|
|
|
|
+import { ref, reactive, onMounted, computed, inject , onBeforeUnmount} from 'vue'
|
|
|
import { useRouter, useRoute } from 'vue-router'
|
|
import { useRouter, useRoute } from 'vue-router'
|
|
|
import { showSuccessToast, showFailToast } from 'vant';
|
|
import { showSuccessToast, showFailToast } from 'vant';
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
|
|
-import {resetPassword,setPassword, userAccount } from '@/api/index'
|
|
|
|
|
|
|
+import {resetPassword,setPassword, userAccount, unbindCaptcha, clearMobile, bindCaptcha, bindMobile } from '@/api/index'
|
|
|
import Message from '@/utils/Message'
|
|
import Message from '@/utils/Message'
|
|
|
import { useStore } from '@/store/index'
|
|
import { useStore } from '@/store/index'
|
|
|
|
|
+import checkRestTime from '@/utils/captcha'
|
|
|
|
|
+import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
const user = useStore('user')
|
|
const user = useStore('user')
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
const router = useRouter()
|
|
@@ -72,6 +106,7 @@ const route = useRoute()
|
|
|
// showFailToast('失败文案')
|
|
// showFailToast('失败文案')
|
|
|
const ruleFormRef = ref<FormInstance>()
|
|
const ruleFormRef = ref<FormInstance>()
|
|
|
const ruleFormRef2 = ref<FormInstance>()
|
|
const ruleFormRef2 = ref<FormInstance>()
|
|
|
|
|
+const ruleFormRef3 = ref<FormInstance>()
|
|
|
interface RuleForm {
|
|
interface RuleForm {
|
|
|
old_password: string
|
|
old_password: string
|
|
|
new_password: string
|
|
new_password: string
|
|
@@ -86,6 +121,10 @@ const ruleForm = reactive<RuleForm>({
|
|
|
const ruleForm2 = reactive({
|
|
const ruleForm2 = reactive({
|
|
|
account: ''
|
|
account: ''
|
|
|
})
|
|
})
|
|
|
|
|
+const ruleForm3 = reactive({
|
|
|
|
|
+ mobile: '',
|
|
|
|
|
+ captcha: '',
|
|
|
|
|
+})
|
|
|
const blurValidate = (formEl: FormInstance | undefined) => {
|
|
const blurValidate = (formEl: FormInstance | undefined) => {
|
|
|
if (!formEl) return
|
|
if (!formEl) return
|
|
|
if(!ruleForm.new_password || !ruleForm.new_password2) return
|
|
if(!ruleForm.new_password || !ruleForm.new_password2) return
|
|
@@ -111,6 +150,15 @@ const rules2 = reactive<FormRules>({
|
|
|
{pattern:'^[a-zA-Z][a-zA-Z0-9]{5,19}$', message: '请输入以字母为开头,长度为6-20位的用户名', trigger: 'blur'}
|
|
{pattern:'^[a-zA-Z][a-zA-Z0-9]{5,19}$', message: '请输入以字母为开头,长度为6-20位的用户名', trigger: 'blur'}
|
|
|
]
|
|
]
|
|
|
})
|
|
})
|
|
|
|
|
+const rules3 = reactive<FormRules>({
|
|
|
|
|
+ mobile:[
|
|
|
|
|
+ {required: true, message: '请输入手机号', trigger: 'blur'},
|
|
|
|
|
+ {pattern:/^(?:(?:\+|00)86)?1[3-9]\d{9}$/, message: '请输入正确手机号', trigger: 'blur'}
|
|
|
|
|
+ ],
|
|
|
|
|
+ captcha:[
|
|
|
|
|
+ {required: true, message: '请输入验证码', trigger: 'blur'},
|
|
|
|
|
+ ]
|
|
|
|
|
+})
|
|
|
const rules = reactive<FormRules>({
|
|
const rules = reactive<FormRules>({
|
|
|
old_password: [
|
|
old_password: [
|
|
|
{ required: true, message: '请输入旧密码', trigger: 'blur' },
|
|
{ required: true, message: '请输入旧密码', trigger: 'blur' },
|
|
@@ -174,11 +222,102 @@ const submitForm2 = async (formEl: FormInstance | undefined) => {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
+const submitForm3 = async (formEl: FormInstance | undefined) => {
|
|
|
|
|
+ if (!formEl) return
|
|
|
|
|
+ await formEl.validate(async(valid, fields) => {
|
|
|
|
|
+ if (valid) {
|
|
|
|
|
+ console.log('submit!')
|
|
|
|
|
+ await clearMobile({captcha: ruleForm3.captcha}).then(async(res) => {
|
|
|
|
|
+ console.log(res)
|
|
|
|
|
+ Message.success(res.data.msg)
|
|
|
|
|
+ await user.getUserProfile()
|
|
|
|
|
+ ruleForm3.mobile = user.profile.mobile
|
|
|
|
|
+ ruleForm3.captcha = ''
|
|
|
|
|
+ clearInterval(interval)
|
|
|
|
|
+ smsMessage.value = '获取验证码'
|
|
|
|
|
+ can_send.value = true
|
|
|
|
|
+ }).catch((error) => {
|
|
|
|
|
+ console.log(error)
|
|
|
|
|
+ Message.error(error.data.msg)
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('error submit!', fields)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+const submitForm4 = async (formEl: FormInstance | undefined) => {
|
|
|
|
|
+ if (!formEl) return
|
|
|
|
|
+ await formEl.validate(async(valid, fields) => {
|
|
|
|
|
+ if (valid) {
|
|
|
|
|
+ console.log('submit!')
|
|
|
|
|
+ await bindMobile({mobile:ruleForm3.mobile, captcha: ruleForm3.captcha}).then(async(res) => {
|
|
|
|
|
+ console.log(res)
|
|
|
|
|
+ Message.success(res.data.msg)
|
|
|
|
|
+ await user.getUserProfile()
|
|
|
|
|
+ ruleForm3.mobile = user.profile.mobile
|
|
|
|
|
+ ruleForm3.captcha = ''
|
|
|
|
|
+ clearInterval(interval)
|
|
|
|
|
+ smsMessage.value = '获取验证码'
|
|
|
|
|
+ can_send.value = true
|
|
|
|
|
+ }).catch((error) => {
|
|
|
|
|
+ console.log(error)
|
|
|
|
|
+ Message.error(error.data.msg)
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('error submit!', fields)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+const can_send = ref<boolean>(true)
|
|
|
|
|
+const smsMessage = ref<'获取验证码' | number>('获取验证码')
|
|
|
|
|
+const VALID = 60
|
|
|
|
|
+
|
|
|
const from = ref<1 | 2>(1)
|
|
const from = ref<1 | 2>(1)
|
|
|
|
|
+const getCaptcha = async() => {
|
|
|
|
|
+ await unbindCaptcha().then((res) => {
|
|
|
|
|
+ console.log(res)
|
|
|
|
|
+ can_send.value = false
|
|
|
|
|
+ smsMessage.value = VALID
|
|
|
|
|
+ settimes()
|
|
|
|
|
+ Message.success('验证码已发送,请注意查收')
|
|
|
|
|
+ }).catch((error) => {
|
|
|
|
|
+ console.log(error)
|
|
|
|
|
+ Message.error(error.data.msg)
|
|
|
|
|
+
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+const getCaptcha2 = async() => {
|
|
|
|
|
+ await bindCaptcha({mobile:ruleForm3.mobile}).then((res) => {
|
|
|
|
|
+ console.log(res)
|
|
|
|
|
+ can_send.value = false
|
|
|
|
|
+ smsMessage.value = VALID
|
|
|
|
|
+ settimes()
|
|
|
|
|
+ Message.success('验证码已发送,请注意查收')
|
|
|
|
|
+ }).catch((error) => {
|
|
|
|
|
+ console.log(error)
|
|
|
|
|
+ Message.error(error.data.msg)
|
|
|
|
|
+
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+let interval
|
|
|
|
|
+const settimes = () => {
|
|
|
|
|
+ const setTimeFn = () => {
|
|
|
|
|
+ (smsMessage.value as number)--
|
|
|
|
|
+ if (smsMessage.value as number < 0 || can_send.value === true) {
|
|
|
|
|
+ clearInterval(interval)
|
|
|
|
|
+ can_send.value = true
|
|
|
|
|
+ smsMessage.value = '获取验证码'
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ interval = setInterval(function() {
|
|
|
|
|
+ setTimeFn()
|
|
|
|
|
+ }, 1000)
|
|
|
|
|
+}
|
|
|
onMounted(async()=>{
|
|
onMounted(async()=>{
|
|
|
from.value = parseInt(localStorage.getItem('from') as string)as 1 | 2
|
|
from.value = parseInt(localStorage.getItem('from') as string)as 1 | 2
|
|
|
await user.getUserProfile()
|
|
await user.getUserProfile()
|
|
|
ruleForm2.account = user.profile?.user_name
|
|
ruleForm2.account = user.profile?.user_name
|
|
|
|
|
+ ruleForm3.mobile = user.profile?.mobile
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
</script>
|
|
</script>
|