|
|
|
@ -9,12 +9,17 @@ |
|
|
|
|
<el-input v-model="form.password" placeholder="请输入密码" show-password type="password" /> |
|
|
|
|
</el-form-item> |
|
|
|
|
</el-form> |
|
|
|
|
<el-button type="primary" class="w-full" @click="onSubmit">授权登陆</el-button> |
|
|
|
|
<div v-if="form.code">code: {{ form.code }}</div> |
|
|
|
|
<el-button type="primary" :disabled="formLoading" class="w-full" @click="onSubmit" |
|
|
|
|
>授权登陆</el-button |
|
|
|
|
> |
|
|
|
|
</div> |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script setup name="MPLogin"> |
|
|
|
|
import { bindWx } from '@/api/login' |
|
|
|
|
|
|
|
|
|
const message = useMessage() // 消息弹窗 |
|
|
|
|
|
|
|
|
|
const form = ref({ |
|
|
|
|
code: undefined, |
|
|
|
|
username: undefined, |
|
|
|
@ -38,13 +43,28 @@ const params = ref({ |
|
|
|
|
scope: 'snsapi_base' // snsapi_base 静默授权获取 open id ;snsapi_userinfo 需要用户授权,获取详细信息 |
|
|
|
|
// state:'code', // a-zA-Z0-9的参数值,最多128字节 |
|
|
|
|
}) |
|
|
|
|
function onSubmit() { |
|
|
|
|
|
|
|
|
|
async function onSubmit() { |
|
|
|
|
// 这些需要判断没有 code 情况拉起授权登陆,有就结束放在重复拉起授权登陆 |
|
|
|
|
if (!form.value.code) { |
|
|
|
|
const access_url = WX_AUTH_URL + `${new URLSearchParams(params.value)}` + REDIRECT |
|
|
|
|
location.href = access_url |
|
|
|
|
} else { |
|
|
|
|
alert(`授权成功!`) |
|
|
|
|
// 校验表单 |
|
|
|
|
if (!formRef.value) return |
|
|
|
|
const valid = await formRef.value.validate() |
|
|
|
|
if (!valid) return |
|
|
|
|
// 提交请求 |
|
|
|
|
formLoading.value = true |
|
|
|
|
try { |
|
|
|
|
await bindWx(form.value) |
|
|
|
|
message.success('绑定成功') |
|
|
|
|
} catch (error) { |
|
|
|
|
console.log(error) |
|
|
|
|
message.success('绑定失败') |
|
|
|
|
} finally { |
|
|
|
|
formLoading.value = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|