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