0848ebc272
部署到群晖 / deploy (push) Successful in 32s
新增 DyQrCodeService,调用 sso.douyin.com 二维码接口; ConfigController 新增 qrcode/qrstatus/qrbind 三个接口; 前端账号列表每行增加"扫码登录"按钮,展示二维码弹窗并自动轮询绑定。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
246 lines
6.3 KiB
TypeScript
246 lines
6.3 KiB
TypeScript
import { defineStore, storeToRefs } from 'pinia';
|
|
import http from './http';
|
|
import { ref, watch } from 'vue';
|
|
import { Response } from '@/types';
|
|
// import { RouteOption } from '@/router/interface';
|
|
// import { addRoutes, removeRoute } from '@/router/dynamicRoutes';
|
|
// import { useSettingStore } from './setting';
|
|
// import { RouteRecordRaw, RouteMeta } from 'vue-router';
|
|
// import { useAuthStore } from '@/plugins';
|
|
// import router from '@/router';
|
|
|
|
// export interface MenuProps {
|
|
// id?: number;
|
|
// name: string;
|
|
// path: string;
|
|
// title?: string;
|
|
// icon?: string;
|
|
// badge?: number | string;
|
|
// target?: '_self' | '_blank';
|
|
// link?: string;
|
|
// component: string;
|
|
// renderMenu?: boolean;
|
|
// permission?: string;
|
|
// parent?: string;
|
|
// children?: MenuProps[];
|
|
// cacheable?: boolean;
|
|
// view?: string;
|
|
// }
|
|
|
|
export const useApiStore = defineStore('coreapi', () => {
|
|
//检查是否已经初始化过了
|
|
async function apiCheckInitStatus() {
|
|
|
|
return { code: 0 }
|
|
// const initStatus = localStorage.getItem('ddns-init');
|
|
// if (initStatus && initStatus === '1') {
|
|
// return { code: 0 }
|
|
// } else {
|
|
// return http
|
|
// .request<any, Response<any>>('/api/init/Check', 'GET')
|
|
// .then((res) => {
|
|
// // console.log(res)
|
|
// if (res.data.code === 0) {
|
|
// // localStorage.setItem('ddns-init', '1')
|
|
// }
|
|
// return res.data;
|
|
// })
|
|
// .finally(() => {
|
|
|
|
// });
|
|
// }
|
|
}
|
|
|
|
//初始化系统配置
|
|
async function apiInit(request: object) {
|
|
console.log(request)
|
|
return http
|
|
.request<any, Response<any>>('/api/init/Init', 'post_json', request)
|
|
.then((res) => {
|
|
// console.log(res)
|
|
|
|
return res.data;
|
|
})
|
|
.finally(() => {
|
|
|
|
});
|
|
}
|
|
//获取配置
|
|
async function apiGetConfig() {
|
|
return http
|
|
.request<any, Response<any>>('/api/config/GetConfig', 'GET')
|
|
.then((res) => {
|
|
console.log(res)
|
|
return res.data;
|
|
})
|
|
.finally(() => {
|
|
|
|
});
|
|
}
|
|
//修改配置
|
|
async function apiUpdateConfig(request: object) {
|
|
return http
|
|
.request<any, Response<any>>('/api/config/UpdateConfig', 'post_json', request)
|
|
.then((res) => {
|
|
console.log(res)
|
|
return res.data;
|
|
})
|
|
.finally(() => {
|
|
|
|
});
|
|
}
|
|
//后台日志
|
|
async function apiGetLogs(param: string) {
|
|
return http.request<any, Response<any>>('/api/logs/GetLog?' + param, 'get').then(r => {
|
|
// console.log(r)
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
//用户信息-头像
|
|
async function apiUserInfo() {
|
|
return http.request<any, Response<any>>('/api/auth/GetUserAvatar', 'get').then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
//密码修改
|
|
async function apiChangePwd(param: object) {
|
|
return http.request<any, Response<any>>('/api/auth/UpdatePwd', 'post_json', param).then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
//StartJobNow
|
|
async function StartJobNow() {
|
|
return http.request<any, Response<any>>('/api/config/ExecuteJobNow', 'get').then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
async function VideoStatics() {
|
|
return http.request<any, Response<any>>('/api/video/statics', 'get').then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
|
|
//视频查询
|
|
async function VideoPageList(param: object) {
|
|
return http.request<any, Response<any>>('/api/video/paged', 'post_json', param).then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
|
|
// 清理数据库中文件不存在的视频记录
|
|
async function VideoCleanup() {
|
|
return http.request<any, Response<any>>('/api/video/cleanup', 'post_json').then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
|
|
// 获取所有视频类型列表
|
|
async function VideoCategories() {
|
|
return http.request<any, Response<any>>('/api/video/categories', 'get').then(r => {
|
|
console.log('VideoCategories 原始响应:', r);
|
|
// 响应拦截器已经处理了 code === 0 的情况,直接返回 data
|
|
// 如果 r 本身就是 Response 对象,返回 r.data
|
|
// 如果 r 已经是 data(拦截器处理后的结果),直接返回
|
|
if (r && typeof r === 'object' && 'code' in r && 'data' in r) {
|
|
return r.data;
|
|
}
|
|
return r;
|
|
}).catch(err => {
|
|
console.error('VideoCategories API 错误:', err);
|
|
throw err;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
//cookies
|
|
async function CookiePageList(param: object) {
|
|
return http.request<any, Response<any>>('/api/config/paged', 'post_json', param).then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
|
|
async function UpdateConfig(param: object) {
|
|
return http.request<any, Response<any>>('/api/config/update', 'post_json', param).then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
|
|
async function deleteCookie(id: string) {
|
|
return http.request<any, Response<any>>('/api/config/delete?id=' + id, 'get').then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
|
|
// 删除指定作者的所有视频数据
|
|
async function DeleteAuthorVideos(authorName: string) {
|
|
return http.request<any, Response<any>>('/api/video/delete-author', 'post_json', { authorName }).then(r => {
|
|
return r.data;
|
|
}).finally(() => {
|
|
|
|
});
|
|
}
|
|
|
|
// 获取抖音扫码登录二维码
|
|
async function QrCodeGet() {
|
|
return http.request<any, Response<any>>('/api/config/qrcode', 'get').then(r => {
|
|
return r.data;
|
|
});
|
|
}
|
|
|
|
// 轮询扫码状态
|
|
async function QrCodeStatus(token: string) {
|
|
return http.request<any, Response<any>>('/api/config/qrstatus?token=' + token, 'get').then(r => {
|
|
return r.data;
|
|
});
|
|
}
|
|
|
|
// 扫码成功后绑定到账号
|
|
async function QrCodeBind(token: string, id: string) {
|
|
return http.request<any, Response<any>>(`/api/config/qrbind?token=${token}&id=${id}`, 'post_json').then(r => {
|
|
return r.data;
|
|
});
|
|
}
|
|
|
|
return {
|
|
deleteCookie,
|
|
UpdateConfig,
|
|
apiCheckInitStatus,
|
|
apiInit,
|
|
apiGetConfig,
|
|
apiUpdateConfig,
|
|
apiGetLogs,
|
|
apiUserInfo,
|
|
apiChangePwd,
|
|
StartJobNow,
|
|
VideoStatics,
|
|
VideoPageList,
|
|
VideoCategories,
|
|
VideoCleanup,
|
|
CookiePageList,
|
|
DeleteAuthorVideos,
|
|
QrCodeGet,
|
|
QrCodeStatus,
|
|
QrCodeBind
|
|
};
|
|
});
|