Browse Source

test:文件分享

master
prr 8 months ago
parent
commit
71dac0501a
  1. 3
      frontend/auto-imports.d.ts
  2. BIN
      frontend/src/assets/lock.png
  3. 11
      frontend/src/components/builtin/FileIcon.vue
  4. 33
      frontend/src/components/setting/SetFilePwd.vue
  5. 16
      frontend/src/system/config.ts
  6. 12
      frontend/src/system/core/FileOs.ts
  7. 1
      frontend/src/system/core/FileSystem.ts
  8. 9
      frontend/src/system/index.ts

3
frontend/auto-imports.d.ts

@ -3,7 +3,6 @@
// @ts-nocheck
// noinspection JSUnusedGlobalSymbols
// Generated by unplugin-auto-import
// biome-ignore lint: disable
export {}
declare global {
const EffectScope: typeof import('vue')['EffectScope']
@ -71,6 +70,6 @@ declare global {
// for type re-export
declare global {
// @ts-ignore
export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
import('vue')
}

BIN
frontend/src/assets/lock.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

11
frontend/src/components/builtin/FileIcon.vue

@ -7,10 +7,14 @@
<div v-if="extname(file?.path || '') === '.ln' || file?.isShare === true" class="ln-img">
<img :src="lnicon" alt="ln" />
</div>
<div v-if="extname(file?.path || '') === '.ln' || file?.isPwd === true" class="lock-img">
<img :src="lockImg" alt="ln" />
</div>
</div>
</template>
<script setup lang="ts">
import lnicon from '@/assets/ln.png';
import lockImg from '@/assets/lock.png'
import { OsFileWithoutContent,extname } from '@/system';
// import { extname } from '../core/Path';
import { ref } from 'vue';
@ -55,5 +59,12 @@ if(props.file && props.file.content) {
width: 80%;
height: 80%;
}
.lock-img {
position: absolute;
bottom: 0;
right: 0;
width: 35%;
height: 35%;
}
}
</style>

33
frontend/src/components/setting/SetFilePwd.vue

@ -20,27 +20,44 @@
<script lang="ts" setup>
import { md5 } from "js-md5";
import { ref } from "vue";
import { ref, onMounted } from "vue";
import { t } from "@/system";
import { fetchGet, getSystemConfig } from "@/system/config";
import { notifySuccess } from "@/util/msg";
import { fetchGet, getApiUrl, setSystemKey, getSystemConfig } from "@/system/config";
import { notifySuccess, notifyError } from "@/util/msg";
const filePwd = ref('')
const setPwd = ref(false)
const params = {
ispwd: true,
pwd: md5(filePwd.value),
salt: getSystemConfig().file.salt
}
async function toSetFilePwd() {
console.log('pwd:', filePwd);
const url = getSystemConfig().userInfo.url + '/file/setfilepwd'
// console.log(':',filePwd.value, md5(filePwd.value));
params.ispwd = filePwd.value === '' ? false : true
const url = getApiUrl() + '/file/setfilepwd'
const header = {
'Salt': 'vIf_wIUedciAd0nTm6qjJA==',
'FilePwd': md5(filePwd.value)
'Salt': params.salt,
'FilePwd': params.pwd
}
await fetchGet(`${getApiUrl()}/file/ispwd?ispwd=${params.ispwd}`)
const res = await fetchGet(url, header)
if (res.ok){
notifySuccess("保存成功111");
notifySuccess("设置文件密码成功");
} else {
params.ispwd = false
params.pwd = ''
notifyError("设置文件密码失败")
}
setSystemKey('file',params)
}
function clearPwd() {
setPwd.value = false
filePwd.value = ''
toSetFilePwd()
}
onMounted(()=>{
setPwd.value = params.ispwd
})
</script>
<style scoped>

16
frontend/src/system/config.ts

@ -29,6 +29,13 @@ export const getSystemConfig = (ifset = false) => {
if (!config.userType) {
config.userType = 'person'
}
if (!config.file) {
config.file = {
ispwd: false,
pwd: '',
salt: 'vIf_wIUedciAd0nTm6qjJA=='
}
}
// 初始化用户信息,若本地存储中已存在则不进行覆盖
if (!config.userInfo) {
config.userInfo = {
@ -208,10 +215,13 @@ export function getWorkflowUrl(){
return config.userInfo.url + '/views/desktop/index.html' + '?uuid=' + getClientId() + '&token=' + config.userInfo.token
}
}
export function fetchGet(url: string) {
export function fetchGet(url: string, headerConfig?: {[key: string]: string}) {
const config = getSystemConfig();
if (config.userType == 'person') {
return fetch(url)
return fetch(url, {
method: 'GET',
headers: headerConfig
})
} else {
return fetch(url, {
method: 'GET',
@ -229,7 +239,7 @@ export function fetchPost(url: string, data: any) {
if (config.userType == 'person') {
return fetch(url, {
method: 'POST',
body: data,
body: data
})
} else {
return fetch(url, {

12
frontend/src/system/core/FileOs.ts

@ -21,7 +21,7 @@ export async function handleReadShareDir(id: number,path: string): Promise<any>
}
return await res.json();
}
// 查看分享文件
// 文件
export async function handleReadShareFile(path: string): Promise<any> {
path = turnServePath(path)
const res = await fetchGet(`${API_BASE_URL}/shareread?path=${path}`);
@ -32,8 +32,7 @@ export async function handleReadShareFile(path: string): Promise<any> {
}
// 删除分享文件
export async function handleShareUnlink(path: string): Promise<any> {
const config = getSystemConfig()
const file = await handleShareDetail(path,config.userInfo.id)
const file = await handleShareDetail(path,getSystemConfig()?.userInfo.id)
path = turnServePath(path)
const res = await fetchGet(`${API_BASE_URL}/sharedelete?senderid=${file.data.fs.sender}&path=${path}&receverid=${file.data.fs.recever}`);
if (!res.ok) {
@ -247,6 +246,13 @@ export const useOsFile = () => {
return [];
},
async readShareFile(path: string) {
const file = await handleShareDetail(path,getSystemConfig()?.userInfo.id)
console.log('文件信息:',file, file.data.fs.is_write);
if(!file.data.fs.is_write) {
alert('该文件不能编辑')
console.log('该文件不能编辑');
return false
}
const response = await handleReadShareFile(path);
if (response && response.data) {
return response.data;

1
frontend/src/system/core/FileSystem.ts

@ -102,6 +102,7 @@ class OsFile extends OsFileInfo {
id?: number; // 文件ID(可选)
isSys?: number; // 文件是否是系统文件(可选)
isShare?: boolean; // 文件是否为共享文件
isPwd?: boolean; //文件是否上锁
/**
* OsFile

9
frontend/src/system/index.ts

@ -433,7 +433,6 @@ export class System {
if (isShareFile(path)) {
const arr = path.split('/')
const fileContent = await this.fs.readShareFile(path)
<<<<<<< HEAD
// console.log('阅读:', fileContent);
if (fileContent !== false) {
const fileName = extname(arr[arr.length-1] || '') || 'link'
@ -441,12 +440,6 @@ export class System {
.get(fileName)
?.func.call(this, path, fileContent || '');
}
=======
const fileName = extname(arr[arr.length - 1] || '') || 'link'
this._flieOpenerMap
.get(fileName)
?.func.call(this, path, fileContent || '');
>>>>>>> 89f84204e655e3df0824fe91c9b17bc8a9d6ad87
} else {
const fileStat = await this.fs.stat(path)
if (!fileStat) {
@ -460,8 +453,6 @@ export class System {
} else {
// 读取文件内容
const fileContent = await this.fs.readFile(path);
console.log('文件内容:', fileContent);
// 从_fileOpenerMap中获取文件扩展名对应的函数并调用
const fileName = extname(fileStat?.name || '') || 'link'
//console.log(fileName)

Loading…
Cancel
Save