Merge pull request 'xbx' (#29) from xbx into master

Reviewed-on: http://git.luyuan.tk/luyuan/beelink/pulls/29
This commit is contained in:
luyuan 2020-10-10 14:08:45 +08:00
commit 96e9284abb
9 changed files with 187 additions and 65 deletions

View File

@ -5,6 +5,20 @@
</div> --> </div> -->
<router-view/> <router-view/>
</template> </template>
<script lang="ts">
import { defineComponent } from 'vue';
import store from './store';
import { getValue } from './utils/common';
export default defineComponent({
setup(){
if(getValue('token')){
store.commit("login")
store.dispatch("setUserInfo");
}
}
})
</script>
<style lang="scss"> <style lang="scss">
.one-line-hide { .one-line-hide {

View File

@ -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
} }

View File

@ -1,15 +1,58 @@
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 phone
* @param type 0 1 * @param password
*/ */
export function sendsms(phone: string, type?: number){ export async function loginpass(phone: string, password: string){
return post('SendSms',{phone, type}) 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 loginpass(phone: string, password: string){ /**
return post("login",{type: 2,username: phone, password: password}) *
*/
export async function userinfo(){
const user = await get<UserInfo>('personalInfo');
console.log(user.data?.img)
return {
head: user.data?.img,
username: user.data?.name,
language: user.data?.language,
currency: user.data?.currency,
zoneStr: user.data?.zoneStr,
memberid: user.data?.memberid,
country: user.data?.country,
live: user.data?.live,
mtongue: user.data?.mtongue,
tlanguage: user.data?.tlanguage,
willsay: user.data?.willsay,
interest: user.data?.interest,
mobile: user.data?.mobile,
email: user.data?.email,
birthday: user.data?.birthday,
video: user.data?.video,
desc: user.data?.desc,
money: user.data?.money
}
} }

View File

@ -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%;
} }
@ -118,7 +117,8 @@
</style> </style>
<script lang="ts"> <script lang="ts">
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(){
@ -169,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 选中的下标 方便赋值与跳转
@ -181,10 +184,13 @@ export default defineComponent({
}) })
} }
return{ return{
list, list,
routeto, routeto,
selnum selnum,
userinfo
} }
} }
}) })

View File

@ -14,17 +14,17 @@
<div class="setting"> <div class="setting">
<div class="item"> <div class="item">
<img src="@/static/images/shijian.png" alt="" class="icon"> <img src="@/static/images/shijian.png" alt="" class="icon">
<div class="name">北京 GMT +08:00</div> <div class="name">{{userinfo.zoneStr}}</div>
<img src="@/static/images/jiantou2.png" alt="" class="down"> <img src="@/static/images/jiantou2.png" alt="" class="down">
</div> </div>
<div class="item"> <div class="item">
<img src="@/static/images/qianbi.png" alt="" class="icon"> <img src="@/static/images/qianbi.png" alt="" class="icon">
<div class="name">人民币</div> <div class="name">{{userinfo.currency}}</div>
<img src="@/static/images/jiantou2.png" alt="" class="down"> <img src="@/static/images/jiantou2.png" alt="" class="down">
</div> </div>
<div class="item"> <div class="item">
<img src="@/static/images/yuyan.png" alt="" class="icon"> <img src="@/static/images/yuyan.png" alt="" class="icon">
<div class="name">中文</div> <div class="name">{{userinfo.language}}</div>
<img src="@/static/images/jiantou2.png" alt="" class="down"> <img src="@/static/images/jiantou2.png" alt="" class="down">
</div> </div>
<div class="item"> <div class="item">
@ -110,7 +110,8 @@
</style> </style>
<script lang="ts"> <script lang="ts">
import router from '@/router'; import router from '@/router';
import { defineComponent, ref } from 'vue'; import store from '@/store';
import { computed, defineComponent, ref } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
export default defineComponent({ export default defineComponent({
@ -148,6 +149,10 @@ export default defineComponent({
route: "/mine/archives" route: "/mine/archives"
} }
] ]
const userinfo = computed(() => {
return store.state.userinfo;
})
function navto(index: number){ function navto(index: number){
router.push({ router.push({
path: nav[index].route path: nav[index].route
@ -156,7 +161,8 @@ export default defineComponent({
return { return {
nav, nav,
types, types,
navto navto,
userinfo
} }
} }
}) })

View File

@ -1,11 +1,27 @@
import { userinfo } from '@/api';
import { createStore } from 'vuex' import { createStore } from 'vuex'
export default createStore({ export default createStore({
state: { state: {
userinfo:{
username: "username",
head: ""
},
islogin: false
}, },
mutations: { mutations: {
setUserInfo(state, userinfo){
state.userinfo = userinfo
},
login(state){
state.islogin = true;
}
}, },
actions: { actions: {
async setUserInfo({ commit }){
const user = await userinfo();
commit('setUserInfo', user);
}
}, },
modules: { modules: {
} }

44
src/types/index.d.ts vendored
View File

@ -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,9 +33,30 @@ export interface VideoInfo {
uid: string; uid: string;
} }
// 返回数据 // 登录返回数据
export interface ResData{ export interface LoginData{
code?: number; api_token: string;
msg?: string; memberid: number;
data?: any; }
// 用户信息
export interface UserInfo {
name: string;
img: string;
language: string;
currency: string;
zoneStr: string;
memberid: string;
country: string;
live: string;
mtongue: string;
tlanguage: string;
willsay: string;
interest:any;
mobile: string;
email: string;
birthday: string;
video: string;
desc: string;
money: string;
} }

View File

@ -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,

View File

@ -2,11 +2,11 @@
<div class="archives"> <div class="archives">
<div class="user-info"> <div class="user-info">
<div class="avatar"> <div class="avatar">
<a-avatar :size="85" shape="circle" src="https://fanyi-cdn.cdn.bcebos.com/static/translation/img/header/logo_40c4f13.svg"> <a-avatar :size="85" shape="circle" :src="userinfo.head">
<template v-slot:icon><UserOutlined /></template> <template v-slot:icon><UserOutlined /></template>
</a-avatar> </a-avatar>
<div class="user-name"> <div class="user-name">
<div class="value">{{ formData.name }}</div> <div class="value">{{ userinfo.username }}</div>
<div class="update-btn" @click="updateUserName">修改</div> <div class="update-btn" @click="updateUserName">修改</div>
</div> </div>
</div> </div>
@ -16,7 +16,7 @@
<div class="input-box country"> <div class="input-box country">
<div class="label">来自国家</div> <div class="label">来自国家</div>
<a-select <a-select
v-model:value="formData.country" v-model:value="userinfo.country"
style="width: 171px" style="width: 171px"
size="small" size="small"
ref="select" ref="select"
@ -29,12 +29,12 @@
</div> </div>
<div class="input-box address"> <div class="input-box address">
<div class="label">居住地</div> <div class="label">居住地</div>
<a-input size="small" v-model:value="formData.address" placeholder="请输入居住地" /> <a-input size="small" v-model:value="userinfo.live" placeholder="请输入居住地" />
</div> </div>
<div class="input-box teach-lang"> <div class="input-box teach-lang">
<div class="label">授课语言</div> <div class="label">授课语言</div>
<a-select <a-select
v-model:value="formData.teachingLang" v-model:value="userinfo.tlanguage"
style="width: 171px" style="width: 171px"
size="small" size="small"
ref="select" ref="select"
@ -77,7 +77,7 @@
<div class="input-box native-lang"> <div class="input-box native-lang">
<div class="label">母语</div> <div class="label">母语</div>
<a-select <a-select
v-model:value="formData.nativeLang" v-model:value="userinfo.mtongue"
style="width: 171px" style="width: 171px"
size="small" size="small"
ref="select" ref="select"
@ -107,7 +107,7 @@
</div> </div>
<div class="input-box introduce"> <div class="input-box introduce">
<div class="label">自我介绍</div> <div class="label">自我介绍</div>
<a-textarea v-model:value="formData.introduce" class="introduce-textarea" /> <a-textarea v-model:value="userinfo.desc" class="introduce-textarea" />
</div> </div>
</div> </div>
</div> </div>
@ -116,11 +116,11 @@
<div class="main-container"> <div class="main-container">
<div class="input-box mailbox"> <div class="input-box mailbox">
<div class="label">邮箱</div> <div class="label">邮箱</div>
<a-input size="small" v-model:value="formData.mail" placeholder="请输入邮箱" /> <a-input size="small" v-model:value="userinfo.mail" placeholder="请输入邮箱" />
</div> </div>
<div class="input-box phone-box"> <div class="input-box phone-box">
<div class="label">手机号</div> <div class="label">手机号</div>
<div class="phone">{{ formData.phone }}</div> <div class="phone">{{ userinfo.mobile }}</div>
<div class="update-btn" @click="togglePhoneModal(true)">更换手机号</div> <div class="update-btn" @click="togglePhoneModal(true)">更换手机号</div>
</div> </div>
</div> </div>
@ -130,13 +130,13 @@
<div class="main-container"> <div class="main-container">
<div class="input-box password-box"> <div class="input-box password-box">
<div class="label">密码</div> <div class="label">密码</div>
<div class="password">{{ formData.password }}</div> <div class="password">************</div>
<div class="update-btn" @click="togglePasswordModal(true)">修改密码</div> <div class="update-btn" @click="togglePasswordModal(true)">修改密码</div>
</div> </div>
<div class="input-box time-zone-box"> <div class="input-box time-zone-box">
<div class="label">时区</div> <div class="label">时区</div>
<a-select <a-select
v-model:value="formData.timeZone" v-model:value="userinfo.zoneStr"
style="width: 171px" style="width: 171px"
size="small" size="small"
ref="select" ref="select"
@ -150,7 +150,7 @@
<div class="input-box currency-box"> <div class="input-box currency-box">
<div class="label">货币</div> <div class="label">货币</div>
<a-select <a-select
v-model:value="formData.currency" v-model:value="userinfo.currency"
style="width: 171px" style="width: 171px"
size="small" size="small"
ref="select" ref="select"
@ -164,7 +164,7 @@
<div class="input-box time-zone"> <div class="input-box time-zone">
<div class="label">语言</div> <div class="label">语言</div>
<a-select <a-select
v-model:value="formData.language" v-model:value="userinfo.language"
style="width: 171px" style="width: 171px"
size="small" size="small"
ref="select" ref="select"
@ -258,9 +258,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, reactive, Ref, ref } from "vue"; import { computed, defineComponent, reactive, Ref, ref } from "vue";
import { UserOutlined, SmileOutlined, PlaySquareOutlined } from '@ant-design/icons-vue'; import { UserOutlined, SmileOutlined, PlaySquareOutlined } from '@ant-design/icons-vue';
import NavBottom from '@/components/NavBottom.vue'; import NavBottom from '@/components/NavBottom.vue';
import store from '@/store';
export default defineComponent({ export default defineComponent({
name: "Archives", name: "Archives",
@ -295,8 +296,11 @@ export default defineComponent({
currency: '人民币', currency: '人民币',
language: '中文', language: '中文',
} }
const userinfo = computed(() => store.state.userinfo)
// //
const formData = reactive(formBasic); const formData = reactive(formBasic);
const modalNode = () => document.getElementsByClassName('modal-container')[0]
/** /**
* 修改用户名 * 修改用户名
* @return { void } * @return { void }
@ -426,7 +430,7 @@ export default defineComponent({
} }
return { return {
modalNode: () => document.getElementsByClassName('modal-container')[0], modalNode,
formData, formData,
updateUserName, updateUserName,
addSpeakLang, addSpeakLang,
@ -446,6 +450,7 @@ export default defineComponent({
passwordForm, passwordForm,
updateUserPassword, updateUserPassword,
submitInfo, submitInfo,
userinfo
} }
} }
}); });