feat: 增加密码管理接口
This commit is contained in:
35
src/apis/password.ts
Normal file
35
src/apis/password.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { cloudService } from './index'
|
||||||
|
import { IPassword, IQueryPassword } from '@/types/password'
|
||||||
|
|
||||||
|
export const addPasswordApi = (password: IPassword): Promise<boolean> =>
|
||||||
|
cloudService({
|
||||||
|
url: '/home-service/password',
|
||||||
|
method: 'post',
|
||||||
|
data: password
|
||||||
|
})
|
||||||
|
|
||||||
|
export const updatePasswordApi = (id: number, password: IPassword): Promise<boolean> =>
|
||||||
|
cloudService({
|
||||||
|
url: `/home-service/password/${id}`,
|
||||||
|
method: 'put',
|
||||||
|
data: password
|
||||||
|
})
|
||||||
|
|
||||||
|
export const deletePasswordApi = (id: number): Promise<boolean> =>
|
||||||
|
cloudService({
|
||||||
|
url: `/home-service/password/${id}`,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
|
||||||
|
export const queryPasswordApi = (query: IQueryPassword): Promise<IPassword[]> =>
|
||||||
|
cloudService({
|
||||||
|
url: '/home-service/password',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
|
||||||
|
export const queryPasswordCategoryApi = (): Promise<string[]> =>
|
||||||
|
cloudService({
|
||||||
|
url: '/home-service/password/category',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
@@ -3,13 +3,13 @@ import { IUser } from '@/types/auth.ts'
|
|||||||
|
|
||||||
export const queryUserApi = (id: number): Promise<IUser> =>
|
export const queryUserApi = (id: number): Promise<IUser> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
url: `/admin-service/user/${id}`,
|
url: `/home-service/user/${id}`,
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
|
|
||||||
export const updateUserApi = (id: number, user: IUser): Promise<boolean> =>
|
export const updateUserApi = (id: number, user: IUser): Promise<boolean> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
url: `/admin-service/user/${id}`,
|
url: `/home-service/user/${id}`,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: user
|
data: user
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import type { IHandleApi } from 'vue3-common/types'
|
import type { IHandleApi } from 'vue3-common/types'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { IPassword } from '@/types/password.ts'
|
import { IPassword, IQueryPassword } from '@/types/password.ts'
|
||||||
|
import {
|
||||||
|
addPasswordApi,
|
||||||
|
deletePasswordApi,
|
||||||
|
queryPasswordApi, queryPasswordCategoryApi,
|
||||||
|
updatePasswordApi
|
||||||
|
} from '@/apis/password'
|
||||||
|
|
||||||
export const usePasswordStore = defineStore('password', {
|
export const usePasswordStore = defineStore('password', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -9,7 +15,7 @@ export const usePasswordStore = defineStore('password', {
|
|||||||
queryInfo: {
|
queryInfo: {
|
||||||
category: '',
|
category: '',
|
||||||
owner: '哥哥'
|
owner: '哥哥'
|
||||||
},
|
} as IQueryPassword,
|
||||||
passwordApiType: 'ADD' as IHandleApi,
|
passwordApiType: 'ADD' as IHandleApi,
|
||||||
categoryList: [] as string[],
|
categoryList: [] as string[],
|
||||||
currentPassword: {
|
currentPassword: {
|
||||||
@@ -26,48 +32,23 @@ export const usePasswordStore = defineStore('password', {
|
|||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
async queryPasswordList() {
|
async queryPasswordList() {
|
||||||
const password: IPassword = {
|
this.passwordList = await queryPasswordApi(this.queryInfo)
|
||||||
id: 1,
|
|
||||||
category: '生活',
|
|
||||||
owner: '哥哥',
|
|
||||||
password: '123123',
|
|
||||||
remark: '12',
|
|
||||||
title: '支付宝',
|
|
||||||
username: '13814079242',
|
|
||||||
website: ''
|
|
||||||
}
|
|
||||||
const password2: IPassword = {
|
|
||||||
id: 2,
|
|
||||||
category: '生活',
|
|
||||||
owner: '哥哥',
|
|
||||||
password: '123123',
|
|
||||||
remark: '12',
|
|
||||||
title: '支付宝',
|
|
||||||
username: '13814079242',
|
|
||||||
website: ''
|
|
||||||
}
|
|
||||||
|
|
||||||
this.passwordList = []
|
|
||||||
this.passwordList.push(password)
|
|
||||||
this.passwordList.push(password2)
|
|
||||||
// this.productList = await queryProductListApi(this.queryInfo)
|
|
||||||
},
|
},
|
||||||
async queryPasswordCategory() {
|
async queryPasswordCategory() {
|
||||||
// this.categoryList = await queryProductCategoryApi()
|
this.categoryList = await queryPasswordCategoryApi()
|
||||||
this.categoryList = ['生活', '工作']
|
|
||||||
},
|
},
|
||||||
async handlePasswordApi(password: IPassword) {
|
async handlePasswordApi(password: IPassword) {
|
||||||
switch (this.passwordApiType) {
|
switch (this.passwordApiType) {
|
||||||
case 'ADD':
|
case 'ADD':
|
||||||
// await addProductApi(product)
|
await addPasswordApi(password)
|
||||||
ElMessage.success('新增密码记录成功')
|
ElMessage.success('新增密码记录成功')
|
||||||
break
|
break
|
||||||
case 'UPDATE':
|
case 'UPDATE':
|
||||||
// await updateProductApi(product.id as number, product)
|
await updatePasswordApi(password.id as number, password)
|
||||||
ElMessage.success('更新密码记录成功')
|
ElMessage.success('更新密码记录成功')
|
||||||
break
|
break
|
||||||
case 'DELETE':
|
case 'DELETE':
|
||||||
// await deleteProductApi(product.id as number)
|
await deletePasswordApi(password.id as number)
|
||||||
ElMessage.success('删除密码记录成功')
|
ElMessage.success('删除密码记录成功')
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -29,3 +29,8 @@ export interface IPassword {
|
|||||||
*/
|
*/
|
||||||
remark: string;
|
remark: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IQueryPassword {
|
||||||
|
category: string;
|
||||||
|
owner: string;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user