Browse Source

add:文件密码箱存储

master
prr 6 months ago
parent
commit
65483277c9
  1. 87
      frontend/src/components/setting/SetFilePwd.vue
  2. 7
      frontend/src/stores/db.ts
  3. 44
      frontend/src/stores/filePwd.ts

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

@ -1,48 +1,73 @@
<template>
<el-button type="primary" :icon="Plus" circle @click="addPwd"/>
<el-button type="primary" :icon="Plus" circle @click="closeDialog(true)"/>
<div class="file-pwd-list-box">
<div class="file-pwd-list">
<div class="pwd-box">
<p>密码提示</p>
<div class="pwd-box" v-for="item in filePwdStore.pwdList">
<p>{{ item.pwdName }}</p>
<el-button type="danger" :icon="Delete" circle @click="addPwd"/>
<el-tag type="primary">default</el-tag>
<el-tag type="primary" v-if="item.isDefault == 1">default</el-tag>
</div>
</div>
<el-pagination
background
layout="prev, pager, next"
:total="filePwdStore.page.total"
:size="filePwdStore.page.size"
:current="filePwdStore.page.current"
/>
</div>
<el-dialog v-model="dialogShow" title="添加密码" width="350px">
<span>
<el-form>
<el-form-item label="密码提示">
<el-input v-model="formData.pwdName"/>
</el-form-item>
<el-form-item label="密码">
<el-input v-model="formData.pwd" show-password/>
</el-form-item>
<el-form-item label="是否为默认密码">
<el-switch v-model="formData.isDefault"/>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="dialogShow = false">
确认
</el-button>
</el-form-item>
</el-form>
</span>
<el-dialog v-model="dialogShow" title="添加密码" width="400px">
<span>
<el-form>
<el-form-item label="密码提示">
<el-input v-model="formData.pwdName"/>
</el-form-item>
<el-form-item label="密码">
<el-input v-model="formData.pwd" show-password/>
</el-form-item>
<el-form-item label="是否为默认密码">
<el-switch
v-model="formData.isDefault"
active-value="1"
inactive-value="0"/>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="addPwd" style="margin: 0 auto;">
确认
</el-button>
</el-form-item>
</el-form>
</span>
</el-dialog>
</template>
<script lang="ts" setup>
import { Plus, Delete } from '@element-plus/icons-vue'
import { reactive, ref } from "vue";
import { reactive, ref, onMounted } from "vue";
import { useFilePwdStore } from '@/stores/filePwd';
const dialogShow = ref(false)
const formData = reactive({
pwdName: '',
pwd: '',
isDefault: ''
})
function addPwd() {
dialogShow.value = true
const filePwdStore: any = useFilePwdStore()
function closeDialog (val: boolean) {
dialogShow.value = val
}
async function addPwd() {
closeDialog(false)
const temp = { ...formData }
await filePwdStore.addPwd(temp)
await initData()
}
async function initData () {
await filePwdStore.getPage()
}
onMounted(async() => {
await initData()
// console.log('', filePwdStore.pwdList, filePwdStore.page.total);
})
// import { t } from "@/system";
// import {
// fetchGet,
@ -78,6 +103,7 @@ function addPwd() {
box-sizing: border-box;
background-color: rgb(248, 247, 247);
overflow-y: scroll;
margin: 10px auto;
.pwd-box {
width: 95%;
@ -103,6 +129,15 @@ function addPwd() {
}
}
}
.el-pagination {
display: flex;
justify-content: center;
}
}
.el-form {
:deep(.el-form-item__label) {
min-width: 80px;
}
}
/* .file-pwd-box {
padding-top: 20px;

7
frontend/src/stores/db.ts

@ -1,6 +1,6 @@
import Dexie from 'dexie';
export type ChatTable = 'prompts' | 'modelslabel' | 'modelslist' | 'chatuser' | 'chatmsg' | 'systemChatRecord' | 'workbenchChatRecord' | 'workbenchChatUser' | 'workbenchSessionList' | 'groupSessionList' | 'workbenchGroupChatRecord' | 'workbenchGroupUserList' | 'workbenchGroupInviteMessage';
export type ChatTable = 'prompts' | 'modelslabel' | 'modelslist' | 'chatuser' | 'chatmsg' | 'systemChatRecord' | 'workbenchChatRecord' | 'workbenchChatUser' | 'workbenchSessionList' | 'groupSessionList' | 'workbenchGroupChatRecord' | 'workbenchGroupUserList' | 'workbenchGroupInviteMessage' | 'filePwdBox';
export const dbInit: any = new Dexie('GodoOSDatabase');
dbInit.version(1).stores({
@ -29,6 +29,8 @@ dbInit.version(1).stores({
// 用户列表
chatuser: '++id,ip,hostname,userName,avatar,mobile,nickName,isOnline,updatedAt,createdAt',
chatmsg: '++id,toUserId,targetIp,senderInfo,reciperInfo,previewMessage,content,type,status,isRead,isMe,readAt,createdAt',
// 文件密码箱
filePwdBox: '++id, pwdName, pwd, isDefault'
}).upgrade((tx: {
workbenchSessionList: any;
workbenchChatUser: any;
@ -82,6 +84,9 @@ export const db = {
return dbInit[tableName].count()
},
async countSearch(tableName: ChatTable, whereObj?: any) {
if (whereObj === undefined) {
return dbInit[tableName].count()
}
return dbInit[tableName].where(whereObj).count()
},
async pageSearch(tableName: ChatTable, page?: number, size?: number, whereObj?: any) {

44
frontend/src/stores/filePwd.ts

@ -0,0 +1,44 @@
import { defineStore } from "pinia"
import { db } from './db.ts'
import { ref } from "vue"
export const useFilePwdStore = defineStore('filePwd', () => {
const page = ref({
current: 1,
size: 6,
total: 0,
pages: 0,
visible: 5
})
const pwdList = ref([])
const addPwd = async (params: any) => {
await db.addOne('filePwdBox', params)
}
const getPage = async () => {
pwdList.value = await db.getPage('filePwdBox', page.value.current, page.value.size)
if (pwdList.value.length == 0) {
page.value.current = page.value.current > 1 ? page.value.current -1 : 1
pwdList.value = await db.getPage('filePwdBox', page.value.current, page.value.size)
}
await getPageCount()
}
const getPageCount = async () => {
page.value.total = await db.countSearch('filePwdBox')
page.value.pages = Math.floor(page.value.total / page.value.size)
// 检查是否有余数
if (page.value.total % page.value.size !== 0) {
// 如果有余数,则加1
page.value.pages++;
}
//console.log(pageCount.value)
return page.value
}
return {
page,
pwdList,
addPwd,
getPage
}
})
Loading…
Cancel
Save