mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
🎨 代码格式化
This commit is contained in:
@@ -14,15 +14,17 @@ const buildTimePlugin = (modes: string[] = []): Plugin => {
|
||||
let _mode = "";
|
||||
return {
|
||||
name: "build-time",
|
||||
config (uc, { mode }) {
|
||||
config(uc, { mode }) {
|
||||
_mode = mode;
|
||||
},
|
||||
transformIndexHtml () {
|
||||
transformIndexHtml() {
|
||||
if (_mode !== "production" && !modes.includes(_mode)) return;
|
||||
return [{
|
||||
tag: "script",
|
||||
children: `window.${buildTimeKey} = '${Math.floor(Date.now() / 1000)}'`,
|
||||
}];
|
||||
return [
|
||||
{
|
||||
tag: "script",
|
||||
children: `window.${buildTimeKey} = '${Math.floor(Date.now() / 1000)}'`,
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -16,18 +16,24 @@ import html2canvas from "html2canvas";
|
||||
* @param {string} filename - 文件名
|
||||
* @returns {Promise<void>} 无返回值
|
||||
*/
|
||||
async function saveCanvasImg (canvas: HTMLCanvasElement, filename: string): Promise<void> {
|
||||
const buffer = new Uint8Array(atob(canvas.toDataURL("image/png").split(",")[1]).split("").map((item) => item.charCodeAt(0)));
|
||||
await dialog.save({
|
||||
defaultPath: filename,
|
||||
filters: [{ name: "图片", extensions: ["png"] }],
|
||||
}).then(async (res) => {
|
||||
if (res === null) return;
|
||||
await fs.writeBinaryFile({
|
||||
path: res,
|
||||
contents: buffer,
|
||||
async function saveCanvasImg(canvas: HTMLCanvasElement, filename: string): Promise<void> {
|
||||
const buffer = new Uint8Array(
|
||||
atob(canvas.toDataURL("image/png").split(",")[1])
|
||||
.split("")
|
||||
.map((item) => item.charCodeAt(0)),
|
||||
);
|
||||
await dialog
|
||||
.save({
|
||||
defaultPath: filename,
|
||||
filters: [{ name: "图片", extensions: ["png"] }],
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res === null) return;
|
||||
await fs.writeBinaryFile({
|
||||
path: res,
|
||||
contents: buffer,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,15 +42,17 @@ async function saveCanvasImg (canvas: HTMLCanvasElement, filename: string): Prom
|
||||
* @param {string} url - 图片链接
|
||||
* @returns {Promise<string>} 图片元素
|
||||
*/
|
||||
export async function saveImgLocal (url: string): Promise<string> {
|
||||
return await http.fetch<ArrayBuffer>(url, {
|
||||
method: "GET",
|
||||
responseType: http.ResponseType.Binary,
|
||||
}).then(async (res) => {
|
||||
const buffer = new Uint8Array(res.data);
|
||||
const blob = new Blob([buffer], { type: "image/png" });
|
||||
return URL.createObjectURL(blob);
|
||||
});
|
||||
export async function saveImgLocal(url: string): Promise<string> {
|
||||
return await http
|
||||
.fetch<ArrayBuffer>(url, {
|
||||
method: "GET",
|
||||
responseType: http.ResponseType.Binary,
|
||||
})
|
||||
.then(async (res) => {
|
||||
const buffer = new Uint8Array(res.data);
|
||||
const blob = new Blob([buffer], { type: "image/png" });
|
||||
return URL.createObjectURL(blob);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +60,7 @@ export async function saveImgLocal (url: string): Promise<string> {
|
||||
* @since Alpha v0.2.0
|
||||
* @returns {string} 背景色
|
||||
*/
|
||||
function getShareImgBgColor (): string {
|
||||
function getShareImgBgColor(): string {
|
||||
let theme = localStorage.getItem("theme");
|
||||
if (theme) {
|
||||
theme = JSON.parse(theme).theme;
|
||||
@@ -72,7 +80,11 @@ function getShareImgBgColor (): string {
|
||||
* @param {number} scale - 缩放比例
|
||||
* @returns {Promise<void>} 无返回值
|
||||
*/
|
||||
export async function generateShareImg (fileName: string, element: HTMLElement, scale: number = 1.2): Promise<void> {
|
||||
export async function generateShareImg(
|
||||
fileName: string,
|
||||
element: HTMLElement,
|
||||
scale: number = 1.2,
|
||||
): Promise<void> {
|
||||
const canvas = document.createElement("canvas");
|
||||
const width = element.clientWidth + 50;
|
||||
const height = element.clientHeight + 50;
|
||||
|
||||
@@ -18,7 +18,7 @@ import { window as TauriWindow } from "@tauri-apps/api";
|
||||
* @param {boolean} visible 是否可见
|
||||
* @returns {void}
|
||||
*/
|
||||
export function createTGWindow (
|
||||
export function createTGWindow(
|
||||
url: string,
|
||||
label: string,
|
||||
title: string,
|
||||
|
||||
@@ -16,7 +16,7 @@ import TGSqlite from "../plugins/Sqlite";
|
||||
* @param {number} timestamp - 时间戳
|
||||
* @returns {string} 日期 2021-01-01 00:00:00
|
||||
*/
|
||||
export function timestampToDate (timestamp: number): string {
|
||||
export function timestampToDate(timestamp: number): string {
|
||||
return new Date(timestamp * 1000).toLocaleString("zh", {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
@@ -34,7 +34,7 @@ export function timestampToDate (timestamp: number): string {
|
||||
* @param {number} progress - 进度
|
||||
* @returns {number} status
|
||||
*/
|
||||
export function getUiafStatus (completed: boolean, progress: number): number {
|
||||
export function getUiafStatus(completed: boolean, progress: number): number {
|
||||
if (progress !== 0 && !completed) {
|
||||
return 1;
|
||||
} else if (progress === 0 && completed) {
|
||||
@@ -51,7 +51,7 @@ export function getUiafStatus (completed: boolean, progress: number): number {
|
||||
* @since Alpha v0.1.3
|
||||
* @returns {Promise<TGApp.Plugins.UIAF.Export>}
|
||||
*/
|
||||
export async function getUiafHeader (): Promise<TGApp.Plugins.UIAF.Export> {
|
||||
export async function getUiafHeader(): Promise<TGApp.Plugins.UIAF.Export> {
|
||||
return {
|
||||
// eslint-disable-next-line camelcase
|
||||
export_app: "Tauri.Genshin",
|
||||
@@ -71,7 +71,7 @@ export async function getUiafHeader (): Promise<TGApp.Plugins.UIAF.Export> {
|
||||
* @param {string} path - UIAF 数据路径
|
||||
* @returns {Promise<boolean>} 是否存在 UIAF 数据
|
||||
*/
|
||||
export async function verifyUiafData (path: string): Promise<boolean> {
|
||||
export async function verifyUiafData(path: string): Promise<boolean> {
|
||||
const fileData: string = await fs.readTextFile(path);
|
||||
const UiafData: TGApp.Plugins.UIAF.Export = JSON.parse(fileData).info;
|
||||
return UiafData.uiaf_version !== undefined;
|
||||
@@ -83,7 +83,7 @@ export async function verifyUiafData (path: string): Promise<boolean> {
|
||||
* @param {string} userPath - UIAF 数据路径
|
||||
* @returns {Promise<string|false>} UIAF 数据
|
||||
*/
|
||||
export async function readUiafData (userPath: string): Promise<string | false> {
|
||||
export async function readUiafData(userPath: string): Promise<string | false> {
|
||||
if (await fs.exists(userPath)) {
|
||||
const fileData = await fs.readTextFile(userPath);
|
||||
if (fileData !== undefined && fileData !== null && fileData !== "" && fileData !== "{}") {
|
||||
@@ -102,7 +102,9 @@ export async function readUiafData (userPath: string): Promise<string | false> {
|
||||
* @param {TGApp.Plugins.UIAF.Achievement[]} achievementData - 成就数据
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function backupUiafData (achievementData: TGApp.Plugins.UIAF.Achievement[]): Promise<void> {
|
||||
export async function backupUiafData(
|
||||
achievementData: TGApp.Plugins.UIAF.Achievement[],
|
||||
): Promise<void> {
|
||||
const savePath = `${await path.appLocalDataDir()}\\userData\\UIAF.json`;
|
||||
await fs.writeTextFile(savePath, JSON.stringify(achievementData, null, 2));
|
||||
}
|
||||
@@ -112,10 +114,10 @@ export async function backupUiafData (achievementData: TGApp.Plugins.UIAF.Achiev
|
||||
* @since Alpha v0.1.4
|
||||
* @returns {Promise<boolean>} 恢复的成就数量
|
||||
*/
|
||||
export async function restoreUiafData (): Promise<boolean> {
|
||||
export async function restoreUiafData(): Promise<boolean> {
|
||||
const uiafPath = `${await path.appLocalDataDir()}\\userData\\UIAF.json`;
|
||||
// 检测是否存在 UIAF 数据
|
||||
if (!await fs.exists(uiafPath)) {
|
||||
if (!(await fs.exists(uiafPath))) {
|
||||
return false;
|
||||
}
|
||||
const uiafData = JSON.parse(await fs.readTextFile(uiafPath)) as TGApp.Plugins.UIAF.Achievement[];
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* @param {string} sql - sql 语句
|
||||
* @return {string} minifiedSql - 减少体积后的 sql 语句
|
||||
*/
|
||||
function minifySql (sql: string): string {
|
||||
function minifySql(sql: string): string {
|
||||
return sql.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user