Merge pull request '出现tokne自动切登录' (#44) from xbx into master

Reviewed-on: http://git.luyuan.tk/luyuan/beelink/pulls/44
This commit is contained in:
luyuan 2020-10-14 16:22:07 +08:00
commit e23b1ba7f7
4 changed files with 50 additions and 13 deletions

View File

@ -7,6 +7,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import router from './router';
import store from './store'; import store from './store';
import { getValue } from './utils/common'; import { getValue } from './utils/common';
@ -15,6 +16,8 @@ export default defineComponent({
if(getValue('token')){ if(getValue('token')){
store.commit("login", true) store.commit("login", true)
store.dispatch("setUserInfo"); store.dispatch("setUserInfo");
}else{
router.push("/")
} }
} }
}) })

View File

@ -3,6 +3,7 @@ import axios from '../config/axiosConfig'
import { AxiosRequestConfig, CustomSuccessData } from 'axios'; import { AxiosRequestConfig, CustomSuccessData } from 'axios';
import { getValue } from '@/utils/common'; import { getValue } from '@/utils/common';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import router from '@/router';
// 泛型接口 // 泛型接口
export interface Get { export interface Get {
@ -10,7 +11,9 @@ export interface Get {
} }
axios.interceptors.response.use((response)=>{ axios.interceptors.response.use((response)=>{
if(response.data.code == 1001){
router.push("/")
}
return response; return response;
},(error)=>{ },(error)=>{
message.error(error.response.data.message) message.error(error.response.data.message)

View File

@ -235,3 +235,24 @@ export async function sendsms(phone: string, type: number): Promise<boolean>{
return false; return false;
} }
} }
/**
*
*/
interface Countries{
id: number;
name: string;
country_code: string;
}
interface Willsay{
languageid: number;
name: string
}
export async function getarchives(): Promise<[Countries[],Willsay[]]>{
return [(await get<Countries[]>("countries")).data, (await get<Willsay[]>("willsay")).data];
}

View File

@ -22,8 +22,8 @@
ref="select" ref="select"
:getPopupContainer="triggerNode => triggerNode.parentNode" :getPopupContainer="triggerNode => triggerNode.parentNode"
> >
<a-select-option v-for="(item, index) in ['美国', '英国']" :key="index" :value="item"> <a-select-option v-for="(item, index) in chiveslist[0]" :key="index" :value="item.name">
{{ item }} {{ item.name }}
</a-select-option> </a-select-option>
</a-select> </a-select>
</div> </div>
@ -57,8 +57,8 @@
ref="select" ref="select"
:getPopupContainer="triggerNode => triggerNode.parentNode" :getPopupContainer="triggerNode => triggerNode.parentNode"
> >
<a-select-option v-for="(item, index) in ['英语', '法语']" :key="index" :value="item"> <a-select-option v-for="(item, index) in chiveslist[1]" :key="index" :value="item.name">
{{ item }} {{ item.name }}
</a-select-option> </a-select-option>
</a-select> </a-select>
<div class="proficiency"> <div class="proficiency">
@ -84,8 +84,8 @@
ref="select" ref="select"
:getPopupContainer="triggerNode => triggerNode.parentNode" :getPopupContainer="triggerNode => triggerNode.parentNode"
> >
<a-select-option v-for="(item, index) in ['英语', '法语']" :key="index" :value="item"> <a-select-option v-for="(item, index) in chiveslist[1]" :key="index" :value="item.name">
{{ item }} {{ item.name }}
</a-select-option> </a-select-option>
</a-select> </a-select>
</div> </div>
@ -259,13 +259,14 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, defineComponent, reactive, Ref, ref } from "vue"; import { computed, defineComponent, onMounted, reactive, Ref, ref } from "vue";
import { UserOutlined, PlaySquareOutlined } from '@ant-design/icons-vue'; import { UserOutlined, PlaySquareOutlined } from '@ant-design/icons-vue';
import NavBottom from '@/components/NavBottom.vue'; import NavBottom from '@/components/NavBottom.vue';
import { uploadflie } from "@/utils/vod" import { uploadflie } from "@/utils/vod"
import store from '@/store'; import store from '@/store';
import smile from "@/static/images/smile.png" import smile from "@/static/images/smile.png"
import smilet from "@/static/images/smilet.png" import smilet from "@/static/images/smilet.png"
import { getarchives } from "@/api/index"
export default defineComponent({ export default defineComponent({
name: "Archives", name: "Archives",
@ -285,9 +286,15 @@ export default defineComponent({
}]; }];
const userinfo = computed(() => store.state.userinfo) const userinfo = computed(() => store.state.userinfo)
// //
const formData = reactive(store.state.userinfo); const formData = reactive(userinfo);
const modalNode = () => document.getElementsByClassName('modal-container')[0] const modalNode = () => document.getElementsByClassName('modal-container')[0]
const chiveslist = ref<unknown>([[],[]]);
onMounted(async ()=>{
chiveslist.value = await getarchives()
})
/** /**
* 修改用户名 * 修改用户名
* @return { void } * @return { void }
@ -300,9 +307,9 @@ export default defineComponent({
* @return { void } * @return { void }
*/ */
function addSpeakLang (): void { function addSpeakLang (): void {
store.state.userinfo.willsay.push({ formData.value.willsay.push({
name: '请选择', name: '请选择',
level: 4 level: 0
}); });
} }
// //
@ -432,6 +439,8 @@ export default defineComponent({
function setlevel(index: number, level: number){ function setlevel(index: number, level: number){
store.state.userinfo.willsay[index].level = level store.state.userinfo.willsay[index].level = level
} }
return { return {
modalNode, modalNode,
formData, formData,
@ -453,11 +462,12 @@ export default defineComponent({
passwordForm, passwordForm,
updateUserPassword, updateUserPassword,
submitInfo, submitInfo,
userinfo, userinfo: formData,
uploads, uploads,
smile, smile,
smilet, smilet,
setlevel setlevel,
chiveslist
} }
} }
}); });