mirror of https://gitee.com/godoos/godoos.git
47 changed files with 2848 additions and 148 deletions
File diff suppressed because it is too large
@ -0,0 +1,79 @@ |
|||||
|
import { Store } from '@tauri-apps/plugin-store'; |
||||
|
|
||||
|
// 创建 Store 实例(使用异步方式获取)
|
||||
|
let store: Store; |
||||
|
|
||||
|
async function getStore(): Promise<Store> { |
||||
|
if (!store) { |
||||
|
store = await Store.load('store.bin'); |
||||
|
} |
||||
|
return store; |
||||
|
} |
||||
|
|
||||
|
// 缓存默认有效期(单位:毫秒)
|
||||
|
const DEFAULT_TTL = 1000 * 60 * 10; // 默认 10 分钟
|
||||
|
|
||||
|
/** |
||||
|
* 设置带过期时间的缓存 |
||||
|
* @param key 缓存键名 |
||||
|
* @param value 缓存值 |
||||
|
* @param ttl 缓存有效时间(毫秒),不传则使用默认值 |
||||
|
*/ |
||||
|
export async function set<T>(key: string, value: T, ttl?: number): Promise<void> { |
||||
|
const storeInstance = await getStore(); |
||||
|
const expireAt = Date.now() + (ttl ?? DEFAULT_TTL); |
||||
|
await storeInstance.set(key, { value, expireAt }); |
||||
|
await storeInstance.save(); // 可选:立即保存
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取缓存值(如果未过期) |
||||
|
* @param key 缓存键名 |
||||
|
* @returns 缓存值或 null(如果未找到或已过期) |
||||
|
*/ |
||||
|
export async function get<T>(key: string): Promise<T | null> { |
||||
|
const storeInstance = await getStore(); |
||||
|
// 使用 storeInstance.has 做初步存在性检查
|
||||
|
const exists = await storeInstance.has(key); |
||||
|
if (!exists) return null; |
||||
|
const entry = await storeInstance.get<{ value: T; expireAt: number }>(key); |
||||
|
|
||||
|
if (!entry) return null; |
||||
|
|
||||
|
const { value, expireAt } = entry; |
||||
|
if (Date.now() > expireAt) { |
||||
|
await storeInstance.delete(key); // 删除过期缓存
|
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return value; |
||||
|
} |
||||
|
/** |
||||
|
* 检查缓存中是否存在指定的键且未过期 |
||||
|
* @param key 缓存键名 |
||||
|
* @returns 如果存在且未过期返回 true,否则返回 false |
||||
|
*/ |
||||
|
export async function has(key: string): Promise<boolean> { |
||||
|
const storeInstance = await getStore(); |
||||
|
// 使用 storeInstance.has 做初步存在性检查
|
||||
|
const exists = await storeInstance.has(key); |
||||
|
if (!exists) return false; |
||||
|
const entry = await storeInstance.get<{ value: any; expireAt: number }>(key); |
||||
|
|
||||
|
if (!entry) return false; |
||||
|
|
||||
|
const { expireAt } = entry; |
||||
|
if (Date.now() > expireAt) { |
||||
|
await storeInstance.delete(key); // 删除已过期的键
|
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
/** |
||||
|
* 清除所有缓存 |
||||
|
*/ |
||||
|
export async function clear(): Promise<void> { |
||||
|
const storeInstance = await getStore(); |
||||
|
await storeInstance.clear(); |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
import { createORM } from '../orm/orm.ts'; |
||||
|
|
||||
|
interface Users { |
||||
|
id?: number; |
||||
|
username: string; |
||||
|
password: string; |
||||
|
nickname: string; |
||||
|
email: string; |
||||
|
phone: string; |
||||
|
isMaster: boolean; |
||||
|
} |
||||
|
|
||||
|
export const userDb = createORM<Users>('users'); |
@ -0,0 +1,21 @@ |
|||||
|
// src/api/local/db.ts
|
||||
|
import Database from '@tauri-apps/plugin-sql'; |
||||
|
import { migrationDatabase } from './migration'; |
||||
|
let dbInstance: Database | null = null; |
||||
|
|
||||
|
export async function connectDatabase(dbPath: string = 'sqlite:godoos.db'): Promise<void> { |
||||
|
if (!dbInstance) { |
||||
|
dbInstance = await Database.load(dbPath); |
||||
|
console.log('✅ 数据库已连接'); |
||||
|
} |
||||
|
} |
||||
|
export async function setupDatabase() { |
||||
|
await connectDatabase(); |
||||
|
await migrationDatabase(); |
||||
|
} |
||||
|
export function getDatabase(): Database { |
||||
|
if (!dbInstance) { |
||||
|
throw new Error('数据库尚未连接,请先调用 connectDatabase'); |
||||
|
} |
||||
|
return dbInstance; |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
import { getDatabase } from './db'; |
||||
|
|
||||
|
export async function migrationDatabase(): Promise<void> { |
||||
|
const db = getDatabase(); |
||||
|
|
||||
|
await db.execute( |
||||
|
`CREATE TABLE IF NOT EXISTS users (
|
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
|
username TEXT NOT NULL UNIQUE, |
||||
|
password TEXT NOT NULL, |
||||
|
nickname TEXT, |
||||
|
email TEXT, |
||||
|
phone TEXT, |
||||
|
isMaster INTEGER DEFAULT 0 |
||||
|
)` |
||||
|
); |
||||
|
console.log('✅ 用户表已初始化'); |
||||
|
} |
@ -0,0 +1,213 @@ |
|||||
|
// src/api/local/orm/orm.ts
|
||||
|
import { getDatabase } from './db'; |
||||
|
import Database from '@tauri-apps/plugin-sql'; |
||||
|
// const userORM = createORM<{ id: number; name: string; role: string }>('users');
|
||||
|
// // 查询并分页
|
||||
|
// await userORM.where({ role: 'admin' }).page(1, 10).select();
|
||||
|
// // 更新数据
|
||||
|
// await userORM.save({ role: 'admin' }).where({ id: 1 }).select();
|
||||
|
// // 统计数量
|
||||
|
// const total = await userORM.where({ role: 'admin' }).count();
|
||||
|
type Model = Record<string, any>; |
||||
|
|
||||
|
interface ORM<T extends Model> { |
||||
|
create: (data: T) => Promise<void>; |
||||
|
update: (id: any, data: Partial<T>) => Promise<void>; |
||||
|
save: (data: Partial<T>) => ORMQueryBuilder<T>; |
||||
|
select: () => Promise<T[]>; |
||||
|
findById: (id: any) => Promise<T | null>; |
||||
|
delete: (id: any) => Promise<void>; |
||||
|
where: (conditions: Record<string, any>) => ORMQueryBuilder<T>; |
||||
|
count: () => Promise<number>; |
||||
|
page: (page: number, pageSize: number) => ORMQueryBuilder<T>; |
||||
|
} |
||||
|
|
||||
|
interface ORMQueryBuilder<T extends Model> { |
||||
|
where: (conditions: Record<string, any>) => ORMQueryBuilder<T>; |
||||
|
count: () => Promise<number>; |
||||
|
page: (page: number, pageSize: number) => ORMQueryBuilder<T>; |
||||
|
select: () => Promise<T[]>; |
||||
|
} |
||||
|
|
||||
|
function createORMQueryBuilder<T extends Model>( |
||||
|
db: Database, |
||||
|
table: string |
||||
|
): ORMQueryBuilder<T> { |
||||
|
let conditions: Record<string, any> = {}; |
||||
|
let limit: number | null = null; |
||||
|
let offset: number | null = null; |
||||
|
|
||||
|
function buildWhereClause(): { clause: string; values: any[] } { |
||||
|
const clauses = []; |
||||
|
const values = []; |
||||
|
|
||||
|
for (const key in conditions) { |
||||
|
if (conditions.hasOwnProperty(key)) { |
||||
|
clauses.push(`${key} = $${values.length + 1}`); |
||||
|
values.push(conditions[key]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const whereClause = clauses.length > 0 ? `WHERE ${clauses.join(' AND ')}` : ''; |
||||
|
return { clause: whereClause, values }; |
||||
|
} |
||||
|
|
||||
|
const queryBuilder: ORMQueryBuilder<T> = { |
||||
|
where: (newConditions: Record<string, any>): ORMQueryBuilder<T> => { |
||||
|
conditions = { ...conditions, ...newConditions }; |
||||
|
return queryBuilder; |
||||
|
}, |
||||
|
count: async (): Promise<number> => { |
||||
|
const { clause, values } = buildWhereClause(); |
||||
|
const query = `SELECT COUNT(*) as count FROM ${table} ${clause}`; |
||||
|
const result: any = await db.select(query, values); |
||||
|
return result[0]?.count || 0; |
||||
|
}, |
||||
|
page: (page: number, pageSize: number): ORMQueryBuilder<T> => { |
||||
|
const newLimit = pageSize; |
||||
|
const newOffset = (page - 1) * pageSize; |
||||
|
limit = newLimit; |
||||
|
offset = newOffset; |
||||
|
return queryBuilder; |
||||
|
}, |
||||
|
select: async (): Promise<T[]> => { |
||||
|
const { clause, values } = buildWhereClause(); |
||||
|
|
||||
|
let limitClause = ''; |
||||
|
if (limit !== null && offset !== null) { |
||||
|
limitClause = `LIMIT ${limit} OFFSET ${offset}`; |
||||
|
} |
||||
|
|
||||
|
const query = `SELECT * FROM ${table} ${clause} ${limitClause}`; |
||||
|
const result = await db.select(query, values); |
||||
|
return result as T[]; |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
return queryBuilder; |
||||
|
} |
||||
|
|
||||
|
function buildWhereClauseFromConditions( |
||||
|
conditions: Record<string, any> |
||||
|
): { clause: string; values: any[] } { |
||||
|
const clauses = []; |
||||
|
const values = []; |
||||
|
|
||||
|
for (const key in conditions) { |
||||
|
if (conditions.hasOwnProperty(key)) { |
||||
|
clauses.push(`${key} = $${values.length + 1}`); |
||||
|
values.push(conditions[key]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const whereClause = clauses.length > 0 ? `WHERE ${clauses.join(' AND ')}` : ''; |
||||
|
return { clause: whereClause, values }; |
||||
|
} |
||||
|
|
||||
|
async function executeUpdate<T extends Model>( |
||||
|
db: Database, |
||||
|
table: string, |
||||
|
data: Partial<T>, |
||||
|
conditions: Record<string, any> |
||||
|
): Promise<void> { |
||||
|
const now = new Date().toISOString(); |
||||
|
const timestampedData = { ...data, updated_at: now }; |
||||
|
const setClause = Object.keys(timestampedData) |
||||
|
.map((key, i) => `${key} = $${i + 1}`) |
||||
|
.join(', '); |
||||
|
const values = Object.values(timestampedData); |
||||
|
|
||||
|
const { clause: whereClause, values: whereValues } = buildWhereClauseFromConditions(conditions); |
||||
|
|
||||
|
const query = `UPDATE ${table} SET ${setClause} ${whereClause}`; |
||||
|
await db.execute(query, [...values, ...whereValues]); |
||||
|
} |
||||
|
|
||||
|
export function createORM<T extends Model>(table: string): ORM<T> { |
||||
|
const db = getDatabase(); |
||||
|
|
||||
|
const ormInstance: ORM<T> = { |
||||
|
create: async (data: T): Promise<void> => { |
||||
|
const now = new Date().toISOString(); |
||||
|
const timestampedData = { |
||||
|
...data, |
||||
|
created_at: now, |
||||
|
updated_at: now, |
||||
|
}; |
||||
|
|
||||
|
const columns = Object.keys(timestampedData).join(', '); |
||||
|
const placeholders = Object.keys(timestampedData) |
||||
|
.map((_, i) => `$${i + 1}`) |
||||
|
.join(', '); |
||||
|
const values = Object.values(timestampedData); |
||||
|
|
||||
|
const query = `INSERT INTO ${table} (${columns}) VALUES (${placeholders})`; |
||||
|
await db.execute(query, values); |
||||
|
}, |
||||
|
|
||||
|
update: async (id: any, data: Partial<T>): Promise<void> => { |
||||
|
const now = new Date().toISOString(); |
||||
|
const timestampedData = { |
||||
|
...data, |
||||
|
updated_at: now, |
||||
|
}; |
||||
|
|
||||
|
const setClause = Object.keys(timestampedData) |
||||
|
.map((key, i) => `${key} = $${i + 1}`) |
||||
|
.join(', '); |
||||
|
|
||||
|
const values = Object.values(timestampedData); |
||||
|
const query = `UPDATE ${table} SET ${setClause} WHERE id = $${values.length + 1}`; |
||||
|
values.push(id); |
||||
|
|
||||
|
await db.execute(query, values); |
||||
|
}, |
||||
|
|
||||
|
save: (data: Partial<T>): ORMQueryBuilder<T> => { |
||||
|
const queryBuilder = createORMQueryBuilder<T>(db, table); |
||||
|
|
||||
|
const originalWhere = queryBuilder.where; |
||||
|
queryBuilder.where = (conditions: Record<string, any>): ORMQueryBuilder<T> => { |
||||
|
const updatedQueryBuilder = originalWhere(conditions); |
||||
|
|
||||
|
updatedQueryBuilder.select = async (): Promise<T[]> => { |
||||
|
await executeUpdate(db, table, data, conditions); |
||||
|
return []; |
||||
|
}; |
||||
|
|
||||
|
return updatedQueryBuilder; |
||||
|
}; |
||||
|
|
||||
|
return queryBuilder; |
||||
|
}, |
||||
|
|
||||
|
select: (): Promise<T[]> => { |
||||
|
return createORMQueryBuilder<T>(db, table).select(); |
||||
|
}, |
||||
|
|
||||
|
findById: async (id: any): Promise<T | null> => { |
||||
|
const query = `SELECT * FROM ${table} WHERE id = $1`; |
||||
|
const result: any = await db.select(query, [id]); |
||||
|
return result.length > 0 ? (result[0] as T) : null; |
||||
|
}, |
||||
|
|
||||
|
delete: async (id: any): Promise<void> => { |
||||
|
const query = `DELETE FROM ${table} WHERE id = $1`; |
||||
|
await db.execute(query, [id]); |
||||
|
}, |
||||
|
|
||||
|
where: (conditions: Record<string, any>): ORMQueryBuilder<T> => { |
||||
|
return createORMQueryBuilder<T>(db, table).where(conditions); |
||||
|
}, |
||||
|
|
||||
|
count: (): Promise<number> => { |
||||
|
return createORMQueryBuilder<T>(db, table).count(); |
||||
|
}, |
||||
|
|
||||
|
page: (page: number, pageSize: number): ORMQueryBuilder<T> => { |
||||
|
return createORMQueryBuilder<T>(db, table).page(page, pageSize); |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
return ormInstance; |
||||
|
} |
@ -0,0 +1,79 @@ |
|||||
|
import { loadScript } from '@/utils/load' |
||||
|
import { get, getToken, setToken,post } from '@/utils/request' |
||||
|
import { getClientId } from '@/utils/uuid' |
||||
|
|
||||
|
export function loginIn(params: any) { |
||||
|
return fetch('/user/login', { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json' |
||||
|
}, |
||||
|
body: JSON.stringify(params) |
||||
|
}).then(res => res.json()).then(res => { |
||||
|
if (res.success) { |
||||
|
setToken(res.data.token) |
||||
|
} |
||||
|
return res |
||||
|
}).catch(err => { throw new Error(err) }) |
||||
|
} |
||||
|
export async function logout() { |
||||
|
return post('user/logout', { |
||||
|
method: 'POST', |
||||
|
}) |
||||
|
} |
||||
|
export async function isLogin() { |
||||
|
const token = getToken() |
||||
|
if (!token) { |
||||
|
return false |
||||
|
} |
||||
|
const res = await get('user/islogin') |
||||
|
return res.success |
||||
|
} |
||||
|
export async function getDingConf() { |
||||
|
await loadScript( |
||||
|
"https://g.alicdn.com/dingding/h5-dingtalk-login/0.21.0/ddlogin.js" |
||||
|
); |
||||
|
|
||||
|
const res = await fetch("user/ding/conf"); |
||||
|
return await res.json(); |
||||
|
} |
||||
|
export async function getThirdpartyList() { |
||||
|
const result = await fetch("/user/thirdparty/list" |
||||
|
); |
||||
|
if (result.ok) { |
||||
|
const data = await result.json(); |
||||
|
if (data.success) return data.data.list; |
||||
|
} |
||||
|
return []; |
||||
|
}; |
||||
|
export async function getEmailCode(email: string) { |
||||
|
const data = { |
||||
|
email: email, |
||||
|
client_id: getClientId(), |
||||
|
} |
||||
|
const res = await fetch('/user/emailcode', { |
||||
|
method: 'POST', |
||||
|
body: JSON.stringify(data), |
||||
|
}) |
||||
|
return await res.json() |
||||
|
} |
||||
|
export async function getSmsCode(phone: string) { |
||||
|
const data = { |
||||
|
phone: phone, |
||||
|
client_id: getClientId(), |
||||
|
} |
||||
|
const res = await fetch('/user/smscode', { |
||||
|
method: 'POST', |
||||
|
body: JSON.stringify(data), |
||||
|
}) |
||||
|
return await res.json() |
||||
|
} |
||||
|
export async function register(params: any) { |
||||
|
return fetch('/user/register', { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json' |
||||
|
}, |
||||
|
body: JSON.stringify(params) |
||||
|
}).then(res => res.json()) |
||||
|
} |
@ -0,0 +1,250 @@ |
|||||
|
import { base64ToBuffer, isBase64 } from '@/utils/file' |
||||
|
import { get, post } from '@/utils/request' |
||||
|
export async function read(path: string, pwd?: string) { |
||||
|
const res = await get(`user/files/read`, { path, pwd }) |
||||
|
return res |
||||
|
} |
||||
|
export async function readFile(path: string, pwd?: string) { |
||||
|
const res = await get(`user/files/readfile`, { path, pwd }) |
||||
|
return res |
||||
|
} |
||||
|
export async function stat(path: string) { |
||||
|
const res = await get(`user/files/stat`, { path }) |
||||
|
return res.data |
||||
|
} |
||||
|
export async function desktop() { |
||||
|
const res = await get(`user/files/desktop`) |
||||
|
if (res && res.success) { |
||||
|
return res.data; |
||||
|
} |
||||
|
return false |
||||
|
} |
||||
|
export async function exists(path: string) { |
||||
|
const res = await get(`user/files/exists`, { path }) |
||||
|
return res.data |
||||
|
|
||||
|
} |
||||
|
export function mkdir(dirPath: string) { |
||||
|
if (dirPath.length < 2 || dirPath.charAt(1) == 'B') { |
||||
|
return false; |
||||
|
} |
||||
|
return post(`user/files/mkdir`, {}, { dirPath }).then(res => res.success) |
||||
|
} |
||||
|
export function rmdir(dirPath: string) { |
||||
|
if (dirPath.length < 3) { |
||||
|
return false; |
||||
|
} |
||||
|
const ext = dirPath.split('.').pop(); |
||||
|
if (ext == 'exe') { |
||||
|
return false; |
||||
|
} |
||||
|
return get(`user/files/rmdir`, { dirPath }).then(res => res.success) |
||||
|
} |
||||
|
export function restore(dirPath: string) { |
||||
|
if (dirPath.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return get(`user/files/restore`, { dirPath }).then(res => res.success) |
||||
|
} |
||||
|
export function favorite(path: string) { |
||||
|
if (path.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
return get(`user/files/favorite`, { path }).then(res => res.success) |
||||
|
} |
||||
|
export function pwd(path: string, pwd: string) { |
||||
|
if (path.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
return get(`user/files/pwd`, { path, pwd }).then(res => res.success) |
||||
|
} |
||||
|
export function unpwd(path: string, pwd: string) { |
||||
|
if (path.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
return get(`user/files/unpwd`, { path, pwd }).then(res => res.success) |
||||
|
} |
||||
|
export function rename(oldPath: string, newPath: string) { |
||||
|
if (oldPath.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
return get(`user/files/rename`, { oldPath, newPath }).then(res => res.success) |
||||
|
|
||||
|
} |
||||
|
export function clear() { |
||||
|
return get(`user/files/clear`).then(res => res.success) |
||||
|
} |
||||
|
export function search(path: string, query: string) { |
||||
|
return get(`user/files/search`, { path, query }).then(res => res.data) |
||||
|
} |
||||
|
export function copy(srcPath: string, dstPath: string) { |
||||
|
if (dstPath.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
return get(`user/files/copyfile`, { srcPath, dstPath }).then(res => res.success) |
||||
|
} |
||||
|
|
||||
|
|
||||
|
export function unlink(path: string) { |
||||
|
if (path.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
const ext = path.split('.').pop(); |
||||
|
if (ext == 'exe') { |
||||
|
return false; |
||||
|
} |
||||
|
return get(`user/files/unlink`, { path }).then(res => res.success) |
||||
|
} |
||||
|
export function parserFormData(content: any, contentType: any) { |
||||
|
if (!content || content == '') { |
||||
|
return new Blob([], { type: 'text/plain;charset=utf-8' }); |
||||
|
} |
||||
|
if (contentType == 'text') { |
||||
|
return new Blob([content], { type: 'text/plain;charset=utf-8' }); |
||||
|
} |
||||
|
else if (contentType == 'base64') { |
||||
|
if (content.indexOf(";base64,") > -1) { |
||||
|
const parts = content.split(";base64,"); |
||||
|
content = parts[1]; |
||||
|
} |
||||
|
content = base64ToBuffer(content); |
||||
|
return new Blob([content]); |
||||
|
} |
||||
|
else if (typeof content === 'object' && content !== null && 'data' in content && Array.isArray(content.data)) { |
||||
|
return new Blob([new Uint8Array(content.data).buffer]); |
||||
|
} |
||||
|
else if (contentType == 'buffer') { |
||||
|
return new Blob([content]); |
||||
|
} |
||||
|
} |
||||
|
export function getFormData(content: any) { |
||||
|
let blobContent: Blob; |
||||
|
//console.log(content)
|
||||
|
if (typeof content === 'string') { |
||||
|
if (content) { // 检查 content 是否为空
|
||||
|
if (isBase64(content)) { |
||||
|
if (content.indexOf(";base64,") > -1) { |
||||
|
const parts = content.split(";base64,"); |
||||
|
content = parts[1]; |
||||
|
} |
||||
|
content = base64ToBuffer(content); |
||||
|
blobContent = new Blob([content]); |
||||
|
} else { |
||||
|
//console.log(content)
|
||||
|
blobContent = new Blob([content], { type: 'text/plain;charset=utf-8' }); |
||||
|
} |
||||
|
} else { |
||||
|
// 处理 content 为空的情况
|
||||
|
blobContent = new Blob([], { type: 'text/plain;charset=utf-8' }); |
||||
|
} |
||||
|
} |
||||
|
else if (content instanceof Blob) { |
||||
|
// 如果是Blob,直接使用
|
||||
|
blobContent = content; |
||||
|
} |
||||
|
else if ('data' in content && Array.isArray(content.data)) { |
||||
|
// 假设data属性是一个字节数组,将其转换为ArrayBuffer
|
||||
|
const arrayBuffer = new Uint8Array(content.data).buffer; |
||||
|
//console.log(arrayBuffer)
|
||||
|
blobContent = new Blob([arrayBuffer]); |
||||
|
} else if (content instanceof ArrayBuffer) { |
||||
|
// 如果已经是ArrayBuffer,直接使用
|
||||
|
blobContent = new Blob([content]); |
||||
|
} |
||||
|
else if (content instanceof Array || content instanceof Object) { |
||||
|
// 如果是数组
|
||||
|
blobContent = new Blob([JSON.stringify(content)], { type: 'text/plain;charset=utf-8' }); |
||||
|
} else { |
||||
|
throw new Error('Unsupported content format'); |
||||
|
} |
||||
|
|
||||
|
const formData = new FormData(); |
||||
|
formData.append('content', blobContent); |
||||
|
return formData |
||||
|
} |
||||
|
export function writeFile(path: string, data: any, pwd?: string) { |
||||
|
|
||||
|
if (path.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
const formData = getFormData(data); |
||||
|
if (!formData) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return post(`user/files/writefile`, formData, { path, pwd }).then(res => { |
||||
|
//console.log(res)
|
||||
|
return res.success |
||||
|
}) |
||||
|
} |
||||
|
export function appendFile(path: string, data: any) { |
||||
|
const formData = getFormData(data); |
||||
|
if (!formData) { |
||||
|
return false; |
||||
|
} |
||||
|
return post(`user/files/appendfile`, formData, { path }).then(res => res.success) |
||||
|
} |
||||
|
export function zip(path: string, ext: string) { |
||||
|
if (path.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
return get(`user/files/zip`, { path, ext }).then(res => res.data) |
||||
|
} |
||||
|
export function unzip(path: string) { |
||||
|
if (path.length < 2) { |
||||
|
return false; |
||||
|
} |
||||
|
return get(`user/files/unzip`, { path }).then(res => res.data) |
||||
|
} |
||||
|
export function isDesktop(path: string) { |
||||
|
const sp = getSp(path) |
||||
|
const arr = path.split(sp) |
||||
|
return arr[1] === 'C' && arr[2] === 'Users' && arr[3] === 'Desktop' && arr.length === 4 |
||||
|
} |
||||
|
export function join(path: string, ...paths: string[]) { |
||||
|
const sp = getSp(path) |
||||
|
if (path.endsWith(sp)) { |
||||
|
return path + paths.join(sp) |
||||
|
} else { |
||||
|
return path + sp + paths.join(sp) |
||||
|
} |
||||
|
} |
||||
|
export function basename(path: string): string { |
||||
|
const sp = getSp(path) |
||||
|
return path.split(sp).pop() || path |
||||
|
} |
||||
|
export function dirname(path: string): string { |
||||
|
const sp = getSp(path) |
||||
|
if (path.indexOf(".") > -1) { |
||||
|
return path.split(sp).slice(0, -1).join(sp) |
||||
|
} else { |
||||
|
return path |
||||
|
} |
||||
|
//return path.split(sp).slice(0, -1).join(sp)
|
||||
|
} |
||||
|
export function getSp(path: string): string { |
||||
|
if (path.indexOf("\\") > -1) { |
||||
|
return "\\" |
||||
|
} else { |
||||
|
return "/" |
||||
|
} |
||||
|
} |
||||
|
export function getParentPath(path: string): string { |
||||
|
const sp = getSp(path) |
||||
|
const arr = path.split(sp); |
||||
|
arr.pop(); |
||||
|
return arr.join(sp); |
||||
|
} |
||||
|
export function getTopPath(path: string) { |
||||
|
const sp = getSp(path) |
||||
|
const arr = path.split(sp); |
||||
|
if (arr[0] == "") { |
||||
|
return arr[1] |
||||
|
} else { |
||||
|
return arr[0] |
||||
|
} |
||||
|
} |
||||
|
export function getExt(path: string) { |
||||
|
return path.split('.').pop() || '' |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
import { get, post } from '@/utils/request' |
||||
|
|
||||
|
export function joinknowledge(path: string) { |
||||
|
return get(`user/files/knowledge`, { path }) |
||||
|
} |
||||
|
export function askknowledge(data: any) { |
||||
|
return post(`user/files/ask`, data).then((res) => res.data) |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
import { get, post } from '@/utils/request' |
||||
|
export function selectUserList(page: number, nickname: string = "") { |
||||
|
return get('/user/sharelist', { page, nickname }).then(res => res.data) |
||||
|
} |
||||
|
export function searchSelectUsers(ids: any) { |
||||
|
return post('/user/searchuser', { ids }).then(res => res.data) |
||||
|
} |
||||
|
export function shareCreate(data: any) { |
||||
|
return post('/user/files/share', data) |
||||
|
} |
||||
|
|
||||
|
// 获取分享用户列表
|
||||
|
export function getShareUserList(path: string) { |
||||
|
return get('user/files/collaboration/editusers', { path }).then(res => res.data) |
||||
|
} |
||||
|
|
||||
|
// 获取编辑历史记录
|
||||
|
export function getEditHistory(path: string, page: string, size: string) { |
||||
|
return get('user/files/collaboration/timeline', { path, page, size }).then(res => res.data) |
||||
|
} |
||||
|
|
||||
|
// 还原编辑数据
|
||||
|
export function restoreEditData(id: string) { |
||||
|
return post('user/files/collaboration/recover', { id }).then(res => res) |
||||
|
} |
@ -0,0 +1,53 @@ |
|||||
|
import { get } from '@/utils/request' |
||||
|
export const getApplyList = (page: number, params?: any) => { |
||||
|
if (params) { |
||||
|
return get('/workflow/datalist?workType=0&knowId=0&limit=10', { |
||||
|
page, |
||||
|
param: 'flowId=' + params, |
||||
|
}).then((res) => res.data) |
||||
|
} else { |
||||
|
return get('/workflow/datalist?workType=0&knowId=0&limit=10', { |
||||
|
page, |
||||
|
}).then((res) => res.data) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export const getMyApply = () => |
||||
|
get('/workflow/list?workType=0&knowId=0').then((res) => res.data) |
||||
|
|
||||
|
export const getMyTask = () => |
||||
|
get('/workflow/list?workType=1&knowId=0').then((res) => res.data) |
||||
|
|
||||
|
export const getTaskList = (page: number, params?: any) => { |
||||
|
if (params) { |
||||
|
return get('/workflow/datalist?workType=1&knowId=0&limit=10', { |
||||
|
page, |
||||
|
param: 'flowId=' + params, |
||||
|
}).then((res) => res.data) |
||||
|
} else { |
||||
|
return get('/workflow/datalist?workType=1&knowId=0&limit=10', { |
||||
|
page, |
||||
|
}).then((res) => res.data) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export const getMyCheckList = (page: number) => |
||||
|
get('/workflow/mychecklist?knowId=0&limit=10', { page }).then( |
||||
|
(res) => res.data |
||||
|
) |
||||
|
|
||||
|
// 我的抄送
|
||||
|
export const getMyCopyList = (page: number, params: any[]) => |
||||
|
get('/workflow/getcopytomelist?&limit=10&knowId=0', { |
||||
|
page, |
||||
|
start_date: params[0], |
||||
|
end_date: params[1], |
||||
|
}).then((res) => res.data) |
||||
|
|
||||
|
// 历史抄送
|
||||
|
export const getCopyFromMeList = (page: number, params: any[]) => |
||||
|
get('/workflow/getcopyfrommelist?&limit=10&knowId=0', { |
||||
|
page, |
||||
|
start_date: params[0], |
||||
|
end_date: params[1], |
||||
|
}).then((res) => res.data) |
Loading…
Reference in new issue