处理用户登陆
This commit is contained in:
@@ -1,83 +1,75 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
const api_user = require("../../api/user.js");
|
||||
const utils_helper = require("../../utils/helper.js");
|
||||
const api_index = require("../../api/index.js");
|
||||
if (!Array) {
|
||||
const _easycom_nut_icon2 = common_vendor.resolveComponent("nut-icon");
|
||||
const _easycom_nut_avatar2 = common_vendor.resolveComponent("nut-avatar");
|
||||
const _easycom_nut_input2 = common_vendor.resolveComponent("nut-input");
|
||||
const _easycom_nut_button2 = common_vendor.resolveComponent("nut-button");
|
||||
(_easycom_nut_icon2 + _easycom_nut_avatar2 + _easycom_nut_button2)();
|
||||
(_easycom_nut_input2 + _easycom_nut_button2)();
|
||||
}
|
||||
const _easycom_nut_icon = () => "../../uni_modules/nutui-uni/components/icon/icon.js";
|
||||
const _easycom_nut_avatar = () => "../../uni_modules/nutui-uni/components/avatar/avatar.js";
|
||||
const _easycom_nut_input = () => "../../uni_modules/nutui-uni/components/input/input.js";
|
||||
const _easycom_nut_button = () => "../../uni_modules/nutui-uni/components/button/button.js";
|
||||
if (!Math) {
|
||||
(_easycom_nut_icon + _easycom_nut_avatar + _easycom_nut_button)();
|
||||
(_easycom_nut_input + _easycom_nut_button)();
|
||||
}
|
||||
const _sfc_main = {
|
||||
__name: "index",
|
||||
setup(__props) {
|
||||
const code = common_vendor.ref("");
|
||||
const redirect_url = common_vendor.ref("");
|
||||
common_vendor.onLoad((options) => {
|
||||
redirect_url.value = options.redirect_url;
|
||||
});
|
||||
common_vendor.onMounted(() => {
|
||||
common_vendor.index.login({
|
||||
provider: "weixin",
|
||||
success(res) {
|
||||
if (res.errMsg === "login:ok") {
|
||||
code.value = res.code;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
const getUserInfo = (res) => {
|
||||
if (code.value === "") {
|
||||
const username = common_vendor.ref("");
|
||||
const password = common_vendor.ref("");
|
||||
const handleLogin = () => {
|
||||
if (username.value === "") {
|
||||
common_vendor.index.showToast({
|
||||
icon: "none",
|
||||
title: "请稍后再试"
|
||||
title: "请输入用户名",
|
||||
icon: "none"
|
||||
});
|
||||
return;
|
||||
}
|
||||
api_user.login(code.value, JSON.stringify(res.detail.userInfo)).then((res2) => {
|
||||
common_vendor.index.__f__("log", "at pages/login/index.vue:63", res2);
|
||||
common_vendor.index.setStorageSync("token", res2.token);
|
||||
common_vendor.index.setStorageSync("uid", res2.user_id);
|
||||
if (res2.is_bind_phone) {
|
||||
utils_helper.navigateTo("/pages/login/phoneAuthorization");
|
||||
return;
|
||||
}
|
||||
if (password.value === "") {
|
||||
common_vendor.index.showToast({
|
||||
title: "授权成功",
|
||||
title: "请输入密码",
|
||||
icon: "none"
|
||||
});
|
||||
if (redirect_url.value !== "undefined") {
|
||||
utils_helper.navigateTo(redirect_url.value);
|
||||
} else {
|
||||
common_vendor.index.navigateBack();
|
||||
}
|
||||
return;
|
||||
}
|
||||
api_index.fetchLogin({
|
||||
user_name: username.value,
|
||||
password: password.value
|
||||
}).then((res) => {
|
||||
common_vendor.index.__f__("log", "at pages/login/index.vue:68", res);
|
||||
common_vendor.index.setStorageSync("token", res.token);
|
||||
common_vendor.index.setStorageSync("uid", res.user.user_id);
|
||||
common_vendor.index.setStorageSync("username", res.user.user_name);
|
||||
common_vendor.index.setStorageSync("role", res.user.role.value);
|
||||
common_vendor.index.showToast({
|
||||
title: "登录成功",
|
||||
icon: "success"
|
||||
});
|
||||
common_vendor.index.switchTab({
|
||||
url: "/pages/index/index"
|
||||
});
|
||||
});
|
||||
};
|
||||
return (_ctx, _cache) => {
|
||||
return {
|
||||
a: common_vendor.p({
|
||||
size: "30",
|
||||
name: "my"
|
||||
}),
|
||||
a: common_vendor.o(($event) => username.value = $event),
|
||||
b: common_vendor.p({
|
||||
size: "80"
|
||||
placeholder: "请输入用户名",
|
||||
clearable: true,
|
||||
label: "用户名",
|
||||
modelValue: username.value
|
||||
}),
|
||||
c: common_vendor.o(getUserInfo),
|
||||
c: common_vendor.o(($event) => password.value = $event),
|
||||
d: common_vendor.p({
|
||||
type: "success",
|
||||
size: "large",
|
||||
["open-type"]: "getUserInfo"
|
||||
placeholder: "请输入密码",
|
||||
clearable: true,
|
||||
label: "密码",
|
||||
type: "password",
|
||||
modelValue: password.value
|
||||
}),
|
||||
e: common_vendor.o(($event) => common_vendor.unref(utils_helper.switchTab)("/pages/index/index")),
|
||||
e: common_vendor.o(handleLogin),
|
||||
f: common_vendor.p({
|
||||
type: "danger",
|
||||
size: "large"
|
||||
type: "primary",
|
||||
block: true
|
||||
})
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user