import router from '@/router'; import store from '@/store'; import { LiveList, LoginData, UserInfo, VideoInfo } from '@/types'; import { saveValue } from '@/utils/common'; import { message } from 'ant-design-vue'; import { del, get, post, put, setToken } from './base' /** * 用户名密码登录 * @param phone 手机号 * @param password 密码 */ export async function loginpass(phone: string, password: string){ const res = await post("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", true); store.dispatch("setUserInfo"); router.push("/mine/archives") } } } /** * 用户头像和用户名字 */ export async function userinfo(){ const user = await get('personalInfo'); // console.log(user.data.img) if(user.code == 1001){ router.push("/") return '未登录'; } 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 } } /** * 获取用户绑定银行卡列表 */ 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>('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>('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; } export async function getvideolist(): Promise { const res = await get>('video') console.log(res) return res.data } /** * 直播列表 */ export async function getlivelist(data?:any):Promise { const res = await get>('live',data); // console.log(res); return res.data } /** * 列表统计 */ interface StatisticList{ liveInfo: any; videoInfo: any; studentInfo: any; } export async function getstatisticlist() { const res = await get('statistics'); // console.log(res) return { liveInfo: res.data.liveInfo, videoInfo:res.data.videoInfo, studentInfo:res.data.studentInfo } } /** * 发布直播 */ interface Liveaddrule{ code: number, msg: string } export async function liveadd(data:any) { const res = await post('live',data); console.log(res) } /** * 发布视频 */ export async function videoadd( form: any,data: any) { const res=await post('video',data) if(res.code==0){ message.success("发布成功") form.value = { title: "", img: "", fileid: "", fileurl: "", fileduration: "", desc: "", video:[""], } } } /** * 视频详情 */ 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; share:number, watch:number } export async function videodetail(data?:any,ifupdate?:number) { const res=await get('video/'+data) if(ifupdate){ console.log(111) return{ title: res.data.title, img: res.data.img, fileid: res.data.fileid, fileurl: res.data.fileurl, fileduration: res.data.fileduration, desc:res.data.desc, video:[res.data.fileurl], } }else{ return { videoid: res.data.videoid, memberid: res.data.memberid, title: res.data.title, img: res.data.img, fileid: res.data.fileid, fileurl: res.data.fileurl, fileduration: res.data.fileduration, status: res.data.status, desc: res.data.desc, deleted_at: res.data.deleted_at, created_at: res.data.created_at, updated_at: res.data.updated_at, watch:res.data.watch, share:res.data.share } } } /** * 删除视频 */ export async function videodel(data:any) { const res = await del('video/'+data); if(res.code==0){ message.success("删除成功") } console.log(res) } /** * 发送验证码 * @param phone 手机号 * @param type 国外1 国内0 */ interface SendSms{ code: number; msg: string; } export async function sendsms(phone: string, type: number): Promise{ const res = await post("SendSms", {phone, type}); console.log(res); if(res.code == 0){ message.success(res.msg); return true; }else{ message.error(res.msg); 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")).data, (await get("willsay")).data]; } /** * 客户端语言 */ interface Language { dictionaryid: number; name: string; alias: string; code :string; position: number; publish: number; value: string; deleted_at: null; created_at: string; updated_at: string; } export async function getlanguages(): Promise{ return (await get("languages")).data; } /** * 修改我的档案 */ export async function putmember(data: unknown): Promise{ return (await put(`member/${store.state.userinfo.memberid}`, data) ) } /** * 直播详情 * */ interface LiveInfo { liveid: number; title: string; img: string; fileid: string; fileurl: string; fileduration: string; vodid: string; vodurl: string; vodduration: string; dateline: string; livetime: number; livenumber: number; status: number; desc: string; deleted_at: null; created_at: string; updated_at: string; } interface StudentList { memberid: number; name: string; img: string; } export async function getliveinfo(id: number){ const liveinfo = (await get(`live/${id}`)).data; const studentlist = (await get("studentLive",{id})).data; return {...liveinfo,studentlist} } /** * 直播日历 */ export async function getdatelist(start: string, end: string) { return (await get("teacherCalendar")).data }