xbx #29
12
src/App.vue
12
src/App.vue
@ -5,6 +5,18 @@
|
|||||||
</div> -->
|
</div> -->
|
||||||
<router-view/>
|
<router-view/>
|
||||||
</template>
|
</template>
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import store from './store';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
setup(){
|
||||||
|
if(store.state.islogin){
|
||||||
|
store.dispatch("setUserInfo");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.one-line-hide {
|
.one-line-hide {
|
||||||
|
@ -1,20 +1,35 @@
|
|||||||
import axios from '../config/axiosConfig'
|
import axios from '../config/axiosConfig'
|
||||||
|
|
||||||
|
import { AxiosRequestConfig, CustomSuccessData } from 'axios';
|
||||||
|
import { getValue } from '@/utils/common';
|
||||||
|
|
||||||
|
// 泛型接口
|
||||||
|
export interface Get {
|
||||||
|
<T>(url: string, params?: object, config?: AxiosRequestConfig): Promise<CustomSuccessData<T>>;
|
||||||
|
}
|
||||||
|
|
||||||
axios.interceptors.response.use((response)=>{
|
axios.interceptors.response.use((response)=>{
|
||||||
return response.data;
|
return response;
|
||||||
},(error)=>{
|
},(error)=>{
|
||||||
return error;
|
return error;
|
||||||
})
|
})
|
||||||
|
|
||||||
function get(url: string,data?: object) {
|
const get: Get = async function (url: string,data?: object) {
|
||||||
return axios.get(url,{params:data})
|
const res = await axios.get(url,{params:data});
|
||||||
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function post(url: string,data?: object) {
|
const post: Get = async function (url: string,data?: object) {
|
||||||
return axios.post(url,data)
|
const res = await axios.post(url,data)
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setToken(){
|
||||||
|
axios.defaults.headers.common['Authorization'] = "Bearer " + getValue("token");
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
get,
|
get,
|
||||||
post
|
post,
|
||||||
|
setToken
|
||||||
}
|
}
|
@ -1,14 +1,10 @@
|
|||||||
import { get, post } from './base'
|
import router from '@/router';
|
||||||
|
import store from '@/store';
|
||||||
|
import { LoginData, UserInfo } from '@/types';
|
||||||
|
import { saveValue } from '@/utils/common';
|
||||||
|
import { message } from 'ant-design-vue';
|
||||||
|
import { get, post, setToken } from './base'
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求验证码
|
|
||||||
* @param phone 手机号
|
|
||||||
* @param type 类型 0国内 1国外
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function sendsms(phone: string, type?: number){
|
|
||||||
return post('SendSms',{phone, type})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名密码登录
|
* 用户名密码登录
|
||||||
@ -16,13 +12,31 @@ export function sendsms(phone: string, type?: number){
|
|||||||
* @param password 密码
|
* @param password 密码
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function loginpass(phone: string, password: string){
|
export async function loginpass(phone: string, password: string){
|
||||||
return post("login",{type: 2,username: phone, password: password})
|
const res = await post<LoginData>("login",{type: 2,username: phone, password: password});
|
||||||
|
console.log(res.code)
|
||||||
|
if(res.code == 1){
|
||||||
|
message.error(res.msg)
|
||||||
|
}else{
|
||||||
|
console.log(res.data)
|
||||||
|
if(!saveValue("token", res.data?.api_token) && !saveValue("memberid", res.data?.memberid) ){
|
||||||
|
message.error("存储错误, 请允许网页使用本地存储!")
|
||||||
|
}else{
|
||||||
|
setToken();
|
||||||
|
store.commit("login");
|
||||||
|
router.push("/mine/archives")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户信息详情
|
* 用户头像和用户名字
|
||||||
*/
|
*/
|
||||||
export function userinfo(){
|
export async function userinfo(){
|
||||||
return get('personalInfo')
|
const user = await get<UserInfo>('personalInfo');
|
||||||
|
console.log(user.data?.img)
|
||||||
|
return {
|
||||||
|
head: user.data?.img,
|
||||||
|
username: user.data?.name
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,8 +2,8 @@
|
|||||||
<div class="menu">
|
<div class="menu">
|
||||||
<div class="user" style="overflow: hidden;">
|
<div class="user" style="overflow: hidden;">
|
||||||
<div class="user" :class="{'seltop': selnum == 0}">
|
<div class="user" :class="{'seltop': selnum == 0}">
|
||||||
<img src="" alt="" class="head">
|
<img :src="userinfo.head" alt="" class="head">
|
||||||
<div class="name">name</div>
|
<div class="name">{{userinfo.username}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -50,7 +50,6 @@
|
|||||||
.head{
|
.head{
|
||||||
width: 57px;
|
width: 57px;
|
||||||
height: 57px;
|
height: 57px;
|
||||||
background-color: #0f0;
|
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
@ -117,9 +116,9 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { userinfo } from '@/api';
|
|
||||||
import router from '@/router';
|
import router from '@/router';
|
||||||
import { defineComponent, ref } from 'vue';
|
import store from '@/store';
|
||||||
|
import { computed, defineComponent, ref } from 'vue';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
setup(){
|
setup(){
|
||||||
@ -170,6 +169,9 @@ export default defineComponent({
|
|||||||
]
|
]
|
||||||
// 当前选中的index
|
// 当前选中的index
|
||||||
const selnum = ref(0);
|
const selnum = ref(0);
|
||||||
|
|
||||||
|
const userinfo = computed(() => store.state.userinfo)
|
||||||
|
console.log(userinfo.value)
|
||||||
/**
|
/**
|
||||||
* 跳转路由与赋值对应的下标
|
* 跳转路由与赋值对应的下标
|
||||||
* @param index 选中的下标 方便赋值与跳转
|
* @param index 选中的下标 方便赋值与跳转
|
||||||
@ -183,13 +185,12 @@ export default defineComponent({
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
userinfo().then((res)=>{
|
|
||||||
console.log(res)
|
|
||||||
})
|
|
||||||
return{
|
return{
|
||||||
list,
|
list,
|
||||||
routeto,
|
routeto,
|
||||||
selnum
|
selnum,
|
||||||
|
userinfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,18 +1,27 @@
|
|||||||
|
import { userinfo } from '@/api';
|
||||||
import { createStore } from 'vuex'
|
import { createStore } from 'vuex'
|
||||||
|
|
||||||
export default createStore({
|
export default createStore({
|
||||||
state: {
|
state: {
|
||||||
userinfo:{
|
userinfo:{
|
||||||
name: "",
|
username: "username",
|
||||||
img: ""
|
head: ""
|
||||||
}
|
},
|
||||||
|
islogin: false
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setUserInfo(state, userinfo){
|
setUserInfo(state, userinfo){
|
||||||
state.userinfo = userinfo
|
state.userinfo = userinfo
|
||||||
|
},
|
||||||
|
login(state){
|
||||||
|
state.islogin = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
async setUserInfo({ commit }){
|
||||||
|
const user = await userinfo();
|
||||||
|
commit('setUserInfo', user);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
modules: {
|
modules: {
|
||||||
}
|
}
|
||||||
|
27
src/types/index.d.ts
vendored
27
src/types/index.d.ts
vendored
@ -2,6 +2,19 @@
|
|||||||
* 只添加了一些必要的参数,并没有写完整,因为剩下的大部分用不到
|
* 只添加了一些必要的参数,并没有写完整,因为剩下的大部分用不到
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// 定义axios
|
||||||
|
import * as axios from 'axios';
|
||||||
|
|
||||||
|
declare module 'axios' {
|
||||||
|
export interface CustomSuccessData<T> {
|
||||||
|
code: number;
|
||||||
|
msg?: string;
|
||||||
|
data?: T;
|
||||||
|
[keys: string]: any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 图片选择
|
// 图片选择
|
||||||
export interface ImgInfo {
|
export interface ImgInfo {
|
||||||
@ -20,10 +33,14 @@ export interface VideoInfo {
|
|||||||
uid: string;
|
uid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回数据
|
// 登录返回数据
|
||||||
export interface ResData<T = any>{
|
export interface LoginData{
|
||||||
code?: number;
|
api_token: string;
|
||||||
msg?: string;
|
memberid: number;
|
||||||
data?: T;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 用户信息
|
||||||
|
export interface UserInfo {
|
||||||
|
name: string;
|
||||||
|
img: string;
|
||||||
|
}
|
@ -149,11 +149,8 @@
|
|||||||
import { defineComponent, reactive, ref } from "vue";
|
import { defineComponent, reactive, ref } from "vue";
|
||||||
import LoginTab from "@/components/login/LoginTab.vue";
|
import LoginTab from "@/components/login/LoginTab.vue";
|
||||||
import NavTop from "@/components/NavTop.vue"
|
import NavTop from "@/components/NavTop.vue"
|
||||||
import { loginpass, sendsms } from '@/api';
|
import { loginpass } from '@/api';
|
||||||
import { message } from 'ant-design-vue';
|
import store from '@/store';
|
||||||
import { ResData } from '@/types';
|
|
||||||
import { saveValue } from '@/utils/common';
|
|
||||||
import router from '@/router';
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "Login",
|
name: "Login",
|
||||||
@ -188,9 +185,6 @@ export default defineComponent({
|
|||||||
*/
|
*/
|
||||||
const getcode: () => void = () => {
|
const getcode: () => void = () => {
|
||||||
console.log(phone.value);
|
console.log(phone.value);
|
||||||
sendsms("86" + phone.value, 0).then((res)=>{
|
|
||||||
console.log(res)
|
|
||||||
})
|
|
||||||
const timestep = setInterval(() => {
|
const timestep = setInterval(() => {
|
||||||
console.log(11112);
|
console.log(11112);
|
||||||
time.value = time.value - 1;
|
time.value = time.value - 1;
|
||||||
@ -202,23 +196,12 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
function login(): void {
|
function login(): void {
|
||||||
console.log(userinfo.phone,userinfo.password)
|
console.log(userinfo.phone,userinfo.password)
|
||||||
|
loginpass(userinfo.phone,userinfo.password).then(()=>{
|
||||||
loginpass(userinfo.phone,userinfo.password).then((res: ResData) =>{
|
store.dispatch("setUserInfo");
|
||||||
console.log(res.code)
|
|
||||||
if(res.code == 1){
|
|
||||||
message.error(res.msg)
|
|
||||||
}else{
|
|
||||||
console.log(res.data)
|
|
||||||
if(!saveValue("token", res.data.api_token)){
|
|
||||||
message.error("存储错误, 请允许网页使用本地存储!")
|
|
||||||
}else{
|
|
||||||
router.push("/mine/archives")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
formLayout,
|
formLayout,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user