Commit 855b8371 authored by chenqikuai's avatar chenqikuai

fix: 修复鉴权两次的问题

parent 953e29f0
This diff is collapsed.
import { eLevel, eNewRoleRelatedToBackEnd, eRole } from '@/types/roleType' import { eLevel, eNewRoleRelatedToBackEnd, eRole } from "@/types/roleType";
import baseAxios from '../index' import baseAxios from "../index";
import { eCheckPhoneStatus } from './types' import { eCheckPhoneStatus } from "./types";
const prefix = '/user' const prefix = "/user";
/* 成功修改后会退出登录 */ /* 成功修改后会退出登录 */
export function userChangePhone(data: { export function userChangePhone(data: {
newPhone: string newPhone: string;
newVerifyCode: string newVerifyCode: string;
phone: string phone: string;
verifyCode: string verifyCode: string;
}) { }) {
return baseAxios({ return baseAxios({
method: 'post', method: "post",
url: prefix + '/change/phone', url: prefix + "/change/phone",
data, data,
}) });
} }
/* 成功修改后会退出登录 */ /* 成功修改后会退出登录 */
export function userChangePwd(data: { export function userChangePwd(data: {
new_pwd: string new_pwd: string;
phone: string phone: string;
verify_code: string verify_code: string;
}) { }) {
return baseAxios({ return baseAxios({
method: 'post', method: "post",
url: '/change/pwd', url: "/change/pwd",
data, data,
}) });
} }
export function userCheckPhone(phone: string) { export function userCheckPhone(phone: string) {
return baseAxios<eCheckPhoneStatus>({ return baseAxios<eCheckPhoneStatus>({
url: prefix + '/check/phone', url: prefix + "/check/phone",
method: 'get', method: "get",
params: { params: {
phone, phone,
}, },
}) });
} }
export function userCreate(data: { export function userCreate(data: {
phone: string phone: string;
staffID?: string staffID?: string;
verifyCode: string verifyCode: string;
}) { }) {
return baseAxios({ return baseAxios({
url: prefix + '/create', url: prefix + "/create",
method: 'POST', method: "POST",
data, data,
}) });
} }
/* 用户可通过验证码或密码登录 */ /* 用户可通过验证码或密码登录 */
export function userLogin(data: { export function userLogin(data: {
is_admin: boolean is_admin: boolean;
phone: string phone: string;
use_pwd: boolean use_pwd: boolean;
pwd?: string pwd?: string;
verify_code?: string verify_code?: string;
}) { }) {
return baseAxios<{ return baseAxios<{
accessToken: string accessToken: string;
level: eLevel level: eLevel;
phone: string phone: string;
role: eNewRoleRelatedToBackEnd role: eNewRoleRelatedToBackEnd;
pri_key: string
pub_key: string
addr: string
}>({ }>({
url: '/login', url: "/login",
method: 'POST', method: "POST",
data, data,
}) });
} }
export function userLogout() { export function userLogout() {
return baseAxios({ return baseAxios({
url: '/logout', url: "/logout",
method: 'GET', method: "GET",
}) });
} }
export function userRegister(data: { phone: string; verify_code: string }) { export function userRegister(data: { phone: string; verify_code: string }) {
return baseAxios<{ return baseAxios<{
accessToken: string accessToken: string;
phone: string phone: string;
role: eNewRoleRelatedToBackEnd role: eNewRoleRelatedToBackEnd;
pri_key: string
pub_key: string
addr: string
}>({ }>({
url: '/user/register', url: "/user/register",
method: 'post', method: "post",
data, data,
}) });
} }
// function padding(all: number): any; // function padding(all: number): any;
......
import baseAxios from '../index' import baseAxios from "../index";
import { iContact, iUserinfo } from './types' import { iContact, iUserinfo } from "./types";
class UserService { class UserService {
static instance: UserService static instance: UserService;
static getInstance() { static getInstance() {
if (!UserService.instance) { if (!UserService.instance) {
UserService.instance = new UserService() UserService.instance = new UserService();
} }
return UserService.instance return UserService.instance;
} }
contact_custom_service(data: { outLetID: number }) { contact_custom_service(data: { outLetID: number }) {
return baseAxios<iContact>({ return baseAxios<iContact>({
url: '/user/contact_custom_service', url: "/user/contact_custom_service",
method: 'post', method: "post",
data, data,
}) });
} }
staffInfo(data: { addrs: string[] }) { staffInfo(data: { addrs: string[] }) {
return baseAxios<{ return baseAxios<{
total: number total: number;
item: (iContact & { out_let_name: string })[] item: (iContact & { out_let_name: string })[];
}>({ }>({
url: '/user/staff_info', url: "/user/staff_info",
method: 'get', method: "get",
params: data, params: data,
paramsSerializer: (data: { addrs: string[] }) => { paramsSerializer: (data: { addrs: string[] }) => {
console.log(data) console.log(data);
return `addrs=${data.addrs.toString()}` return `addrs=${data.addrs.toString()}`;
}, },
}) });
} }
userInfo(data: { addrs: string[] }) { userInfo(data: { addrs: string[] }) {
return baseAxios<iUserinfo[]>({ return baseAxios<iUserinfo[]>({
url: '/user/user_info', url: "/user/user_info",
method: 'get', method: "get",
params: data, params: data,
paramsSerializer: (data: { addrs: string[] }) => { paramsSerializer: (data: { addrs: string[] }) => {
console.log(data) console.log(data);
return `addrs=${data.addrs.toString()}` return `addrs=${data.addrs.toString()}`;
}, },
}) });
}
getChatToken() {
return baseAxios<{ addr: string; token: string }>({
url: "/chat_info",
});
} }
} }
export default UserService export default UserService;
import { eRole } from './roleType' import { eRole } from "./roleType";
export interface iUserMsg { export interface iUserMsg {
token: string token: string;
role: eRole role: eRole;
role2: eRole role2: eRole;
userInfo: { userInfo: {
phone?: string phone?: string;
addr: string addr?: string;
pri_key: string };
pub_key: string
[key: string]: any
}
} }
import { dispatchLoginAction } from '@/store/chatStore' import { dispatchLoginAction } from "@/store/chatStore";
import { iUserMsg } from '@/types/userMsg' import { iUserMsg } from "@/types/userMsg";
import Bridge from '@/utils/jsBridge2' import Bridge from "@/utils/jsBridge2";
import userAvatarUrl from '@/assets/icons/avatar.png' import userAvatarUrl from "@/assets/icons/avatar.png";
import staffAvatarUrl from '@/assets/icons/staff.png' import staffAvatarUrl from "@/assets/icons/staff.png";
import { eRole } from '@/types/roleType' import { eRole } from "@/types/roleType";
const USER_MSG = 'USER_MSG' const USER_MSG = "USER_MSG";
export function setUserMsg(msg: iUserMsg) { export function setUserMsg(msg: iUserMsg) {
dispatchLoginAction('login') const { token } = msg;
const { token } = msg
new Bridge().bridge_sendToken({ new Bridge().bridge_sendToken({
msg, msg,
url: url:
window.location.protocol + window.location.protocol +
'//' + "//" +
window.location.host + window.location.host +
'/proxyApi/api/v1', "/proxyApi/api/v1",
}) });
localStorage.setItem(USER_MSG, JSON.stringify(msg)) localStorage.setItem(USER_MSG, JSON.stringify(msg));
} }
export function getUserMsg(): iUserMsg | undefined { export function getUserMsg(): iUserMsg | undefined {
const value = localStorage.getItem(USER_MSG) const value = localStorage.getItem(USER_MSG);
return (value && JSON.parse(value)) || undefined return (value && JSON.parse(value)) || undefined;
} }
export function deleteUserMsg() { export function deleteUserMsg() {
dispatchLoginAction('logout') dispatchLoginAction("logout");
localStorage.removeItem(USER_MSG) localStorage.removeItem(USER_MSG);
} }
export function getCurrentUserAvatarUrl() { export function getCurrentUserAvatarUrl() {
if (getUserMsg()?.role === eRole.staff) { if (getUserMsg()?.role === eRole.staff) {
return staffAvatarUrl return staffAvatarUrl;
} else if (getUserMsg()?.role === eRole.user) { } else if (getUserMsg()?.role === eRole.user) {
return userAvatarUrl return userAvatarUrl;
} else { } else {
return userAvatarUrl return userAvatarUrl;
} }
} }
...@@ -9,15 +9,22 @@ ...@@ -9,15 +9,22 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { userChangePwd, userCheckPhone, userCreate, userLogin, userRegister } from '@/service/UserManagementService' import {
import { eCheckPhoneStatus } from '@/service/UserManagementService/types' userChangePwd,
import { eSmsType, sendVerifyCode } from '@/service/VerificationService' userCheckPhone,
import { eNewRoleRelatedToBackEnd, eRole } from '@/types/roleType' userCreate,
import transformRole from '@/utils/transformRole' userLogin,
import { setUserMsg } from '@/utils/userMsg' userRegister,
import { defineComponent } from 'vue' } from "@/service/UserManagementService";
import LoginService from './Login/LoginService' import { eCheckPhoneStatus } from "@/service/UserManagementService/types";
import { eAccountType } from './Login/types' import { eSmsType, sendVerifyCode } from "@/service/VerificationService";
import { dispatchLoginAction } from "@/store/chatStore";
import { eNewRoleRelatedToBackEnd, eRole } from "@/types/roleType";
import transformRole from "@/utils/transformRole";
import { setUserMsg } from "@/utils/userMsg";
import { defineComponent } from "vue";
import LoginService from "./Login/LoginService";
import { eAccountType } from "./Login/types";
export default defineComponent({ export default defineComponent({
provide(): object { provide(): object {
...@@ -29,48 +36,50 @@ export default defineComponent({ ...@@ -29,48 +36,50 @@ export default defineComponent({
loginByPwdFunc: this.loginByPwdFunc, loginByPwdFunc: this.loginByPwdFunc,
setPwdFunc: this.setPwdFunc, setPwdFunc: this.setPwdFunc,
modifyPwdFunc: this.modifyPwdFunc, modifyPwdFunc: this.modifyPwdFunc,
} };
}, },
methods: { methods: {
async sendSmsFunc(phone: string, smsType?: eSmsType) { async sendSmsFunc(phone: string, smsType?: eSmsType) {
return sendVerifyCode({ return sendVerifyCode({
phone: phone, phone: phone,
smsType: smsType !== undefined ? smsType : eSmsType.registerOrLogin, smsType: smsType !== undefined ? smsType : eSmsType.registerOrLogin,
}) });
}, },
async accountStatusCheckFunc(phone: string) { async accountStatusCheckFunc(phone: string) {
const ret = await userCheckPhone(phone) const ret = await userCheckPhone(phone);
if (ret && ret.code === 200) { if (ret && ret.code === 200) {
if (ret.data === eCheckPhoneStatus.staff || ret.data === eCheckPhoneStatus.user) { if (
return eAccountType.REG_PDSET ret.data === eCheckPhoneStatus.staff ||
ret.data === eCheckPhoneStatus.user
) {
return eAccountType.REG_PDSET;
} else if (ret.data === eCheckPhoneStatus.no_reg) { } else if (ret.data === eCheckPhoneStatus.no_reg) {
return eAccountType.NO_REG return eAccountType.NO_REG;
} }
} }
}, },
async registerFunc(phone: string, code: string) { async registerFunc(phone: string, code: string) {
const ret = await userRegister({ const ret = await userRegister({
phone, phone,
verify_code: code verify_code: code,
}) });
if (ret.code === 200) { if (ret.code === 200) {
const { accessToken, role, phone, addr, pri_key, pub_key } = ret.data const { accessToken, role, phone } = ret.data;
setUserMsg({ setUserMsg({
token: accessToken, token: accessToken,
role: role === eNewRoleRelatedToBackEnd.ACM ? eRole.staff : eRole.user, role:
role === eNewRoleRelatedToBackEnd.ACM ? eRole.staff : eRole.user,
role2: transformRole(role), role2: transformRole(role),
userInfo: { userInfo: {
phone: phone, phone: phone,
addr,
pri_key,
pub_key
}, },
}) });
dispatchLoginAction("login");
this.$router.push({ this.$router.push({
name: 'Home', name: "Home",
}) });
} else { } else {
throw new Error(ret.msg) throw new Error(ret.msg);
} }
}, },
async loginByCodeFunc(phone: string, code: string) { async loginByCodeFunc(phone: string, code: string) {
...@@ -78,73 +87,72 @@ export default defineComponent({ ...@@ -78,73 +87,72 @@ export default defineComponent({
is_admin: false, is_admin: false,
use_pwd: false, use_pwd: false,
verify_code: code, verify_code: code,
phone: phone phone: phone,
}) });
if (ret.code === 200) { if (ret.code === 200) {
const { accessToken, phone, role, pri_key, pub_key, addr } = ret.data const { accessToken, phone, role } = ret.data;
setUserMsg({ setUserMsg({
token: accessToken, token: accessToken,
role2: transformRole(role), role2: transformRole(role),
role: eNewRoleRelatedToBackEnd.ACM === role ? eRole.staff : eRole.user, role:
eNewRoleRelatedToBackEnd.ACM === role ? eRole.staff : eRole.user,
userInfo: { userInfo: {
phone, phone,
addr, },
pri_key, });
pub_key dispatchLoginAction("login");
}
})
this.$router.push({ this.$router.push({
name: 'Home' name: "Home",
}) });
} }
}, },
async loginByPwdFunc(phone: string, pwd: string, config = { gohome: true }) { async loginByPwdFunc(
phone: string,
pwd: string,
config = { gohome: true }
) {
const ret = await userLogin({ const ret = await userLogin({
is_admin: false, is_admin: false,
use_pwd: true, use_pwd: true,
pwd, pwd,
phone: phone phone: phone,
}) });
if (ret.code === 200) { if (ret.code === 200) {
const { accessToken, phone, role, addr, pub_key, pri_key } = ret.data const { accessToken, phone, role } = ret.data;
setUserMsg({ setUserMsg({
token: accessToken, token: accessToken,
role2: transformRole(role), role2: transformRole(role),
role: eNewRoleRelatedToBackEnd.ACM === role ? eRole.staff : eRole.user, role:
eNewRoleRelatedToBackEnd.ACM === role ? eRole.staff : eRole.user,
userInfo: { userInfo: {
phone, phone,
addr, },
pub_key, });
pri_key dispatchLoginAction("login");
} config.gohome &&
}) this.$router.push({
config.gohome && this.$router.push({ name: "Home",
name: 'Home' });
})
} else { } else {
throw new Error(ret.msg) throw new Error(ret.msg);
} }
}, },
async setPwdFunc(phone: string, code: string, pwd: string) { async setPwdFunc(phone: string, code: string, pwd: string) {
const ret = await userChangePwd({ const ret = await userChangePwd({
new_pwd: pwd, new_pwd: pwd,
phone, phone,
verify_code: code verify_code: code,
}) });
if (ret.code !== 200) { if (ret.code !== 200) {
throw new Error(ret.msg) throw new Error(ret.msg);
} }
await this.loginByPwdFunc(phone, pwd, { gohome: true }) await this.loginByPwdFunc(phone, pwd, { gohome: true });
}, },
async modifyPwdFunc(phone: string, originalPwd: string, newPwd: string) { async modifyPwdFunc(phone: string, originalPwd: string, newPwd: string) {
console.log(phone, originalPwd, newPwd) console.log(phone, originalPwd, newPwd);
}, },
}, },
}) });
</script> </script>
<style lang="less"> <style lang="less"></style>
</style>
...@@ -74,12 +74,8 @@ ...@@ -74,12 +74,8 @@
class="mt-24" class="mt-24"
@seeMore="$router.push({ name: 'LoanList', params: { mode: mode } })" @seeMore="$router.push({ name: 'LoanList', params: { mode: mode } })"
/> />
<Skeleton <div style="margin-top: 20px" v-if="state.allProductList"></div>
:row="3" <Skeleton :row="3" :loading="skeLoading" v-if="state.allProductList">
:loading="skeLoading"
style="margin-top: 20px"
v-if="state.allProductList"
>
<LoanCard <LoanCard
v-for="item in state.allProductList" v-for="item in state.allProductList"
:key="item.uuid" :key="item.uuid"
......
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