beelink/src/api/index.ts

238 lines
4.9 KiB
TypeScript
Raw Normal View History

2020-10-10 02:19:38 +00:00
import router from '@/router';
import store from '@/store';
2020-10-14 07:30:29 +00:00
import { LiveList, LoginData, UserInfo, VideoInfo } from '@/types';
2020-10-10 02:19:38 +00:00
import { saveValue } from '@/utils/common';
import { message } from 'ant-design-vue';
import { get, post, setToken } from './base'
2020-09-24 07:33:12 +00:00
2020-10-09 01:45:13 +00:00
2020-10-10 00:59:54 +00:00
/**
*
* @param phone
* @param password
*/
2020-10-10 02:19:38 +00:00
export async function loginpass(phone: string, password: string){
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)
2020-10-14 07:30:29 +00:00
if(!saveValue("token", res.data.api_token) && !saveValue("memberid", res.data.memberid) ){
2020-10-10 02:19:38 +00:00
message.error("存储错误, 请允许网页使用本地存储!")
}else{
setToken();
2020-10-14 01:32:12 +00:00
store.commit("login", true);
2020-10-10 06:34:23 +00:00
store.dispatch("setUserInfo");
2020-10-10 02:19:38 +00:00
router.push("/mine/archives")
}
}
2020-10-09 06:31:10 +00:00
}
2020-10-10 00:59:54 +00:00
/**
2020-10-10 02:19:38 +00:00
*
2020-10-10 00:59:54 +00:00
*/
2020-10-10 02:19:38 +00:00
export async function userinfo(){
const user = await get<UserInfo>('personalInfo');
2020-10-14 07:30:29 +00:00
// console.log(user.data.img)
2020-10-10 06:34:23 +00:00
if(user.code == 1001){
2020-10-12 08:44:22 +00:00
// router.push("/")
2020-10-10 06:34:23 +00:00
return '未登录';
}
2020-10-10 02:19:38 +00:00
return {
2020-10-14 07:30:29 +00:00
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
2020-10-10 02:19:38 +00:00
}
}
2020-10-12 02:50:58 +00:00
/**
*
*/
interface Wallect {
wallectid: number;
memberid: number;
type: number;
account: string;
mname: string;
bankcode: string;
bankname: string;
deleted_at: null;
created_at: string;
updated_at: string;
typeName: string;
}
export async function getwallect(){
const res = await get<Array<Wallect>>('wallect')
console.log(res)
}
/**
*
*/
interface Teacherliked {
memberid: number;
name: string;
img: string;
live: string;
birthday: string;
mtongue: string;
interest: string;
}
export async function getteacherliked(){
const res = await get<Array<Teacherliked>>('teacherliked');
console.log(res)
}
/**
*
*/
interface VideoList{
videoid: number;
memberid: number;
title: string;
img: string;
fileid: string;
fileurl: string;
fileduration: string;
status: number;
desc: string;
deleted_at: null;
created_at: string;
updated_at: string;
statusname: string;
}
2020-10-14 07:30:29 +00:00
export async function getvideolist(): Promise<VideoList[]> {
2020-10-12 02:50:58 +00:00
const res = await get<Array<VideoList>>('video')
console.log(res)
2020-10-14 07:30:29 +00:00
return res.data
2020-10-12 02:50:58 +00:00
}
/**
*
*/
2020-10-14 00:57:57 +00:00
2020-10-14 07:30:29 +00:00
export async function getlivelist(data?:any):Promise<LiveList[]> {
2020-10-14 00:57:57 +00:00
const res = await get<Array<LiveList>>('live',data);
// console.log(res);
return res.data
2020-10-12 09:27:05 +00:00
}
/**
*
*/
2020-10-14 02:25:49 +00:00
interface StatisticList{
liveInfo: any;
videoInfo: any;
studentInfo: any;
}
2020-10-12 09:27:05 +00:00
export async function getstatisticlist() {
const res = await get<StatisticList>('statistics');
// console.log(res)
return {
2020-10-14 07:30:29 +00:00
liveInfo: res.data.liveInfo,
videoInfo:res.data.videoInfo,
studentInfo:res.data.studentInfo
2020-10-12 09:27:05 +00:00
}
2020-10-14 00:57:57 +00:00
}
/**
*
*/
interface Liveaddrule{
code:number,
msg:string
2020-10-14 02:25:49 +00:00
}
export async function liveadd(data:any) {
2020-10-14 00:57:57 +00:00
const res = await post<Liveaddrule>('live',data);
console.log(res)
2020-10-14 07:30:29 +00:00
}
/**
*
*/
export async function videoadd(data:any) {
const res=await post<Liveaddrule>('video',data)
}
/**
*
*/
interface VideoDetail{
videoid: number;
memberid: number;
title: string;
img: string;
fileid: string;
fileurl: string;
fileduration: string;
status: number;
desc: string;
deleted_at: null;
created_at: string;
updated_at: string;
}
export async function videodetail(data?:any) {
const res=await get<VideoDetail>('video/'+data)
return res.data
}
/**
*
*/
export async function videodel(data:any) {
const res = await post<Liveaddrule>('live',data);
console.log(res)
2020-10-14 02:25:49 +00:00
}
/**
*
* @param phone
* @param type 1 0
*/
interface SendSms{
code: number;
msg: string;
}
export async function sendsms(phone: string, type: number): Promise<boolean>{
const res = await post<SendSms>("SendSms", {phone, type});
console.log(res);
if(res.code == 0){
message.success(res.msg);
return true;
}else{
message.error(res.msg);
return false;
}
}