diff --git a/oa/api/app/app_user.go b/oa/api/app/app_user.go index eaab0e9..add4a6e 100644 --- a/oa/api/app/app_user.go +++ b/oa/api/app/app_user.go @@ -90,12 +90,6 @@ func appUserPatch(x *rest.X) (any, error) { return nil, err } optsMap := make(map[string]interface{}) - if opts.AppID != nil { - optsMap["app_id"] = opts.AppID - } - if opts.UserID != nil { - optsMap["user_id"] = opts.UserID - } if opts.Status != nil { optsMap["status"] = opts.Status } diff --git a/oa/errs/errors.go b/oa/errs/errors.go index dc1108f..84262a4 100644 --- a/oa/errs/errors.go +++ b/oa/errs/errors.go @@ -31,6 +31,7 @@ func JsonErrorResponse(x *rest.X, err error) { func errIter(err error) (code int, msg string) { code = 50000 + msg = err.Error() switch e := err.(type) { case *CodeErr: code = e.Code @@ -44,7 +45,7 @@ func errIter(err error) (code int, msg string) { msg = "db error" } case interface{ Unwrap() error }: - return errIter(e.Unwrap()) + code, _ = errIter(e.Unwrap()) default: if errors.Is(e, gorm.ErrRecordNotFound) { code = NotFound.Code diff --git a/oa/models/app.gen.go b/oa/models/app.gen.go index 948024a..c3921c2 100644 --- a/oa/models/app.gen.go +++ b/oa/models/app.gen.go @@ -33,46 +33,54 @@ type AppList struct { type AppUserGet struct { ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"` + UserID string `json:"user_id" parse:"json"` AppID string `json:"app_id" parse:"path"` - UserID string `json:"user_id" parse:"path"` } type AppUserPatch struct { ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"` - AppID *string `json:"app_id" parse:"path"` - UserID *string `json:"user_id" parse:"path"` Status *string `json:"status" parse:"json"` + AppID string `json:"app_id" parse:"path"` } type AppUserDelete struct { - ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"` + ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@app_user_id"` + AppID string `json:"app_id" parse:"path"` } type AppUserList struct { AppID *string `json:"app_id" parse:"path"` - UserID *string `json:"user_id" parse:"path"` + UserID *string `json:"user_id" parse:"json"` Status *string `json:"status" parse:"json"` } type AppUserPost struct { - AppID string `json:"app_id" parse:"path"` - UserID string `json:"user_id" parse:"path"` Status string `json:"status" parse:"json"` + UserID string `json:"user_id" parse:"json"` + AppID string `json:"app_id" parse:"path"` } type ResourceList struct { CreatedAt *time.Time `json:"created_at" parse:"query"` UpdatedAt *time.Time `json:"updated_at" parse:"query"` - AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"json"` + AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"path"` } type ResourcePost struct { - AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"json"` Name string `json:"name" gorm:"primaryKey" parse:"json"` Des string `json:"des" parse:"json"` + AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"path"` } type ResourceDelete struct { - AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"json"` Name string `json:"name" gorm:"primaryKey" parse:"json"` + AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" parse:"path"` +} + +type ResourceGet struct { + AppID string `json:"app_id" parse:"path"` +} + +type ResourcePatch struct { + AppID string `json:"app_id" parse:"path"` } diff --git a/oa/models/app.go b/oa/models/app.go index 65c0ba2..4f22c5c 100644 --- a/oa/models/app.go +++ b/oa/models/app.go @@ -20,10 +20,10 @@ type App struct { type AppUser struct { BaseModel - AppID string `json:"app_id" methods:"get,*list,post" parse:"path"` + AppID string `json:"app_id" methods:"get,list,post,patch,delete" parse:"path"` App *App `json:"-" gorm:"foreignKey:AppID;references:ID"` - UserID string `json:"user_id" methods:"get,*list,post" parse:"path"` + UserID string `json:"user_id" methods:"get,*list,post" parse:"json"` User *User `json:"-" gorm:"foreignKey:UserID;references:ID"` Status string `json:"status" methods:"post,*patch,*list" parse:"json"` @@ -63,7 +63,7 @@ func (m *AppUser) AfterUpdate(tx *gorm.DB) error { type Resource struct { BaseDate - AppID string `json:"app_id" gorm:"primaryKey;type:varchar(32)" methods:"post,list,delete" parse:"json"` + AppID string `json:"app_id" methods:"get,list,post,patch,delete" parse:"path"` App *App `json:"-" gorm:"foreignKey:AppID;references:ID"` Name string `json:"name" gorm:"primaryKey" methods:"post,delete" parse:"json"` Des string `json:"des" methods:"post" parse:"json"` diff --git a/oa/models/user.gen.go b/oa/models/user.gen.go index 76a7e8d..a33cd82 100644 --- a/oa/models/user.gen.go +++ b/oa/models/user.gen.go @@ -2,12 +2,6 @@ package models import () -type UserLogin struct { - ID string `json:"id" parse:"path@user_id"` - Pwd string `json:"pwd" parse:"json"` - Typ string `json:"typ" parse:"json"` -} - type UserGet struct { ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_id"` } @@ -45,28 +39,31 @@ type UserList struct { } type UserRoleGet struct { - ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"` + ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"` + UserID string `json:"user_id" parse:"path"` } type UserRolePatch struct { ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"` Status *string `json:"status" parse:"json"` + UserID string `json:"user_id" parse:"path"` } type UserRoleDelete struct { ID string `json:"id" gorm:"primaryKey;type:varchar(32)" parse:"path@user_role_id"` UserID string `json:"user_id" parse:"path"` - RoleID string `json:"role_id" parse:"path"` + RoleID string `json:"role_id" parse:"json"` AppID string `json:"app_id" parse:"json"` } type UserRolePost struct { - UserID string `json:"user_id" parse:"path"` - RoleID string `json:"role_id" parse:"path"` Status string `json:"status" parse:"json"` + RoleID string `json:"role_id" parse:"json"` AppID string `json:"app_id" parse:"json"` + UserID string `json:"user_id" parse:"path"` } type UserRoleList struct { Status *string `json:"status" parse:"json"` + UserID string `json:"user_id" parse:"path"` } diff --git a/oa/models/user.go b/oa/models/user.go index 5b6c6e3..0b2357c 100644 --- a/oa/models/user.go +++ b/oa/models/user.go @@ -24,7 +24,7 @@ type User struct { type UserRole struct { BaseModel - UserID string `json:"user_id" methods:"post,delete" parse:"json"` + UserID string `json:"user_id" methods:"get,list,post,patch,delete" parse:"path"` User *User `json:"-" gorm:"foreignKey:UserID;references:ID"` RoleID string `json:"role_id" methods:"post,delete" parse:"json"` diff --git a/oaweb/.gitignore b/oaweb/.gitignore index 4a7f73a..c7f5776 100644 --- a/oaweb/.gitignore +++ b/oaweb/.gitignore @@ -1,4 +1,5 @@ # Nuxt dev/build outputs +.nuxt .output .data .nuxt diff --git a/oaweb/composables/api/access.ts b/oaweb/composables/api/access.ts new file mode 100644 index 0000000..cd0405d --- /dev/null +++ b/oaweb/composables/api/access.ts @@ -0,0 +1,34 @@ +// +// Copyright (C) 2024 veypi +// 2024-10-11 00:18:06 +// Distributed under terms of the MIT license. +// + +import webapi from "./webapi" +import * as models from "./models" +export interface ListOpts { + app_id: String + user_id?: String + role_id?: String + name?: String +} +export interface ListQuery { + created_at?: Date + updated_at?: Date +} +export function List(json: ListOpts, query: ListQuery) { + return webapi.Get(`/access`, { json, query }) +} + +export interface PostOpts { + app_id: String + user_id?: String + role_id?: String + name: String + t_id: String + level: Number +} +export function Post(json: PostOpts) { + return webapi.Post(`/access`, { json }) +} + diff --git a/oaweb/composables/api/app.ts b/oaweb/composables/api/app.ts index 3c134c6..c22b682 100644 --- a/oaweb/composables/api/app.ts +++ b/oaweb/composables/api/app.ts @@ -1,12 +1,112 @@ -import webapi from "./gocliRequest" -import * as components from "./mainComponents" -export * from "./mainComponents" - -/** - * @description - * @param params - * @param req - */ -export function login(pa: string, req: components.AppReq, params: components.AppReqParams) { - return webapi.get(`/api/app/login/${pa}`, {"params":params, "req":req}) +// +// Copyright (C) 2024 veypi +// 2024-10-11 00:18:06 +// Distributed under terms of the MIT license. +// + +import webapi from "./webapi" +import * as models from "./models" +export interface GetOpts { + name: String +} +export function Get(app_id: String, json: GetOpts) { + return webapi.Get(`/app/${app_id}`, { json }) +} + +export function AppUserDelete(app_user_id: String, app_id: String) { + return webapi.Delete(`/app/${app_id}/app_user/${app_user_id}`, { }) +} + +export function ResourcePatch(app_id: String) { + return webapi.Patch(`/app/${app_id}/resource`, { }) +} + +export interface PatchOpts { + name?: String + icon?: String + des?: String + participate?: String + init_role_id?: String +} +export function Patch(app_id: String, json: PatchOpts) { + return webapi.Patch(`/app/${app_id}`, { json }) +} + +export interface PostOpts { + name: String + icon: String + des: String + participate: String +} +export function Post(json: PostOpts) { + return webapi.Post(`/app`, { json }) +} + +export interface AppUserListOpts { + user_id?: String + status?: String +} +export function AppUserList(app_id: String, json: AppUserListOpts) { + return webapi.Get(`/app/${app_id}/app_user`, { json }) +} + +export interface ResourceListQuery { + created_at?: Date + updated_at?: Date +} +export function ResourceList(app_id: String, query: ResourceListQuery) { + return webapi.Get(`/app/${app_id}/resource`, { query }) +} + +export interface ResourcePostOpts { + name: String + des: String +} +export function ResourcePost(app_id: String, json: ResourcePostOpts) { + return webapi.Post(`/app/${app_id}/resource`, { json }) } + +export function Delete(app_id: String) { + return webapi.Delete(`/app/${app_id}`, { }) +} + +export interface ListOpts { + name?: String +} +export function List(json: ListOpts) { + return webapi.Get(`/app`, { json }) +} + +export interface AppUserGetOpts { + user_id: String +} +export function AppUserGet(app_user_id: String, app_id: String, json: AppUserGetOpts) { + return webapi.Get(`/app/${app_id}/app_user/${app_user_id}`, { json }) +} + +export function ResourceGet(app_id: String) { + return webapi.Get(`/app/${app_id}/resource`, { }) +} + +export interface AppUserPatchOpts { + status?: String +} +export function AppUserPatch(app_user_id: String, app_id: String, json: AppUserPatchOpts) { + return webapi.Patch(`/app/${app_id}/app_user/${app_user_id}`, { json }) +} + +export interface AppUserPostOpts { + status: String + user_id: String +} +export function AppUserPost(app_id: String, json: AppUserPostOpts) { + return webapi.Post(`/app/${app_id}/app_user`, { json }) +} + +export interface ResourceDeleteOpts { + name: String +} +export function ResourceDelete(app_id: String, json: ResourceDeleteOpts) { + return webapi.Delete(`/app/${app_id}/resource`, { json }) +} + diff --git a/oaweb/composables/api/index.ts b/oaweb/composables/api/index.ts index e9bebf2..a124b77 100644 --- a/oaweb/composables/api/index.ts +++ b/oaweb/composables/api/index.ts @@ -1,14 +1,13 @@ -/* - * index.ts - * Copyright (C) 2024 veypi - * 2024-08-02 17:40 - * Distributed under terms of the MIT license. - */ - -import * as user from './user' -import * as app from './app' +import * as user from "./user" +import * as token from "./token" +import * as role from "./role" +import * as app from "./app" +import * as access from "./access" export default { user, - app + token, + role, + app, + access } diff --git a/oaweb/composables/api/mainComponents.ts b/oaweb/composables/api/mainComponents.ts deleted file mode 100644 index b4926c0..0000000 --- a/oaweb/composables/api/mainComponents.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Code generated by goctl. DO NOT EDIT. - -export interface AppReq { - password: string -} -export interface AppReqParams { - username: string -} - -export interface AppResp { - id: number - name: string - token: string - expireAt: string -} - -export interface LoginReqParams { - pwd: string - client: string - typ: string -} - -export interface RegReq { - username: string - pwd: string -} - -export interface AuthHeaders { - authorization: string -} - - - -export interface UserResp { - id: string - created: number - updated: number - username: string - nickname: string - email: string - phone: string - icon: string - status: number // 状态(0:ok,1:disabled) - used: number - space: number -} - diff --git a/oaweb/composables/api/models.ts b/oaweb/composables/api/models.ts new file mode 100644 index 0000000..70eca39 --- /dev/null +++ b/oaweb/composables/api/models.ts @@ -0,0 +1,79 @@ +export interface Access { + app_id: String + app?: App + user_id?: String + user?: User + role_id?: String + role?: Role + name: String + t_id: String + level: Number +} +export interface App { + name: String + icon: String + des: String + participate: String + init_role_id?: String + init_role?: Role + init_url: String + user_count: Number + key: String +} +export interface AppUser { + app_id: String + app?: App + user_id: String + user?: User + status: String +} +export interface Resource { + app_id: String + app?: App + name: String + des: String +} +export interface Role { + name: String + des: String + app_id: String + app?: App + user_count: Number + access: any +} +export interface Testb { + test_id: String + test?: Test + name: String +} +export interface Test { + name: String +} +export interface Token { + user_id: String + user?: User + app_id: String + app?: App + expired_at: Date + over_perm: String + device: String +} +export interface User { + username: String + nickname: String + icon: String + email: String + phone: String + status: Number + salt: String + code: String +} +export interface UserRole { + user_id: String + user?: User + role_id: String + role?: Role + app_id: String + app?: App + status: String +} diff --git a/oaweb/composables/api/role.ts b/oaweb/composables/api/role.ts new file mode 100644 index 0000000..121f2fa --- /dev/null +++ b/oaweb/composables/api/role.ts @@ -0,0 +1,41 @@ +// +// Copyright (C) 2024 veypi +// 2024-10-11 00:18:06 +// Distributed under terms of the MIT license. +// + +import webapi from "./webapi" +import * as models from "./models" +export interface ListOpts { + name?: String +} +export function List(json: ListOpts) { + return webapi.Get(`/role`, { json }) +} + +export function Get(role_id: String) { + return webapi.Get(`/role/${role_id}`, { }) +} + +export interface PatchOpts { + name?: String + des?: String + app_id?: String +} +export function Patch(role_id: String, json: PatchOpts) { + return webapi.Patch(`/role/${role_id}`, { json }) +} + +export function Delete(role_id: String) { + return webapi.Delete(`/role/${role_id}`, { }) +} + +export interface PostOpts { + name: String + des: String + app_id: String +} +export function Post(json: PostOpts) { + return webapi.Post(`/role`, { json }) +} + diff --git a/oaweb/composables/api/token.ts b/oaweb/composables/api/token.ts new file mode 100644 index 0000000..44d8220 --- /dev/null +++ b/oaweb/composables/api/token.ts @@ -0,0 +1,56 @@ +// +// Copyright (C) 2024 veypi +// 2024-10-11 00:18:06 +// Distributed under terms of the MIT license. +// + +import webapi from "./webapi" +import * as models from "./models" +export function Delete(token_id: String) { + return webapi.Delete(`/token/${token_id}`, {}) +} + +export interface ListOpts { + user_id: String + app_id: String +} +export function List(json: ListOpts) { + return webapi.Get(`/token`, { json }) +} + +export interface TokenSaltOpts { + username: String + typ?: String +} + +// keep +export function TokenSalt(json: TokenSaltOpts) { + return webapi.Post(`/token/salt`, { json }) +} + +export interface PostOpts { + user_id: String + token?: String + salt?: String + code?: String + app_id?: String + expired_at?: Date + over_perm?: String + device?: String +} +export function Post(json: PostOpts) { + return webapi.Post(`/token`, { json }) +} + +export function Get(token_id: String) { + return webapi.Get(`/token/${token_id}`, {}) +} + +export interface PatchOpts { + expired_at?: Date + over_perm?: String +} +export function Patch(token_id: String, json: PatchOpts) { + return webapi.Patch(`/token/${token_id}`, { json }) +} + diff --git a/oaweb/composables/api/user.ts b/oaweb/composables/api/user.ts index bfb06d4..4aa4763 100644 --- a/oaweb/composables/api/user.ts +++ b/oaweb/composables/api/user.ts @@ -1,33 +1,92 @@ -import webapi from "./gocliRequest" -import * as components from "./mainComponents" -export * from "./mainComponents" +// +// Copyright (C) 2024 veypi +// 2024-10-11 00:18:06 +// Distributed under terms of the MIT license. +// -/** - * @description - * @param req - */ -export function reg(req: components.RegReq) { - return webapi.post(`/api/user`, {"req":req}) +import webapi from "./webapi" +import * as models from "./models" +export interface PostOpts { + username: String + nickname?: String + icon?: String + email?: String + phone?: String + salt: String + code: String +} +export function Post(json: PostOpts) { + return webapi.Post(`/user`, { json }) +} + +export function UserRoleGet(user_role_id: String, user_id: String) { + return webapi.Get(`/user/${user_id}/user_role/${user_role_id}`, {}) +} + +export interface UserRolePatchOpts { + status?: String +} +export function UserRolePatch(user_role_id: String, user_id: String, json: UserRolePatchOpts) { + return webapi.Patch(`/user/${user_id}/user_role/${user_role_id}`, { json }) +} + +export interface UserRoleDeleteOpts { + role_id: String + app_id: String +} +export function UserRoleDelete(user_role_id: String, user_id: String, json: UserRoleDeleteOpts) { + return webapi.Delete(`/user/${user_id}/user_role/${user_role_id}`, { json }) +} + +export interface UserRolePostOpts { + status: String + role_id: String + app_id: String +} +export function UserRolePost(user_id: String, json: UserRolePostOpts) { + return webapi.Post(`/user/${user_id}/user_role`, { json }) +} + +export interface UserLoginOpts { + pwd: String + typ: String } -/** - * @description - * @param params - */ -export function login(id: string, params: components.LoginReqParams) { - return webapi.head(`/api/user/${id}`, {"params":params}) +export function Get(user_id: String) { + return webapi.Get(`/user/${user_id}`, {}) } -/** - * @description - */ -export function list() { - return webapi.get>(`/api/user`, {}) +export function Delete(user_id: String) { + return webapi.Delete(`/user/${user_id}`, {}) +} + +export interface UserRoleListOpts { + status?: String +} +export function UserRoleList(user_id: String, json: UserRoleListOpts) { + return webapi.Get(`/user/${user_id}/user_role`, { json }) } -/** - * @description - */ -export function get(id: number) { - return webapi.get(`/api/user/${id}`, {}) +export interface PatchOpts { + username?: String + nickname?: String + icon?: String + email?: String + phone?: String + status?: Number } +export function Patch(user_id: String, json: PatchOpts) { + return webapi.Patch(`/user/${user_id}`, { json }) +} + +export interface ListOpts { + username?: String + nickname?: String + email?: String + phone?: String + status?: Number +} +export function List(json: ListOpts) { + return webapi.Get(`/user`, { json }) +} + diff --git a/oaweb/composables/api/gocliRequest.ts b/oaweb/composables/api/webapi.ts similarity index 61% rename from oaweb/composables/api/gocliRequest.ts rename to oaweb/composables/api/webapi.ts index 82bc1fc..18ce1ee 100644 --- a/oaweb/composables/api/gocliRequest.ts +++ b/oaweb/composables/api/webapi.ts @@ -1,10 +1,8 @@ -/* - * gocliRequest.ts - * Copyright (C) 2024 veypi - * 2024-08-02 17:14 - * Distributed under terms of the MIT license. - */ - +// +// Copyright (C) 2024 veypi +// 2024-10-11 00:21:45 +// Distributed under terms of the MIT license. +// import axios, { AxiosError, type AxiosResponse } from 'axios'; @@ -18,6 +16,7 @@ import axios, { AxiosError, type AxiosResponse } from 'axios'; axios.defaults.withCredentials = true const proxy = axios.create({ withCredentials: true, + baseURL: "/api/", headers: { 'content-type': 'application/json;charset=UTF-8', }, @@ -84,36 +83,49 @@ const responseFailed = (error: AxiosError) => { proxy.interceptors.response.use(responseSuccess, responseFailed) - interface data { - params?: any - req?: any - headers?: any + json?: any + query?: any + form?: any + header?: any +} + +function transData(d: data) { + let opts = { params: d.query, data: {}, headers: {} as any } + if (d.form) { + opts.data = d.form + opts.headers['content-type'] = 'application/x-www-form-urlencoded' + } + if (d.json) { + opts.data = d.json + opts.headers['content-type'] = 'application/json' + } + if (d.header) { + opts.headers = Object.assign(opts.headers, d.header) + } + return opts } export const webapi = { - get(url: string, req: data): Promise { - return proxy.request({ method: 'get', url: url, headers: req.headers, data: req.req, params: req.params }) + Get(url: string, req: data): Promise { + return proxy.request(Object.assign({ method: 'get', url: url }, transData(req))) }, - head(url: string, req: data): Promise { - return proxy.request({ method: 'head', url: url, headers: req.headers, data: req.req, params: req.params }) + Head(url: string, req: data): Promise { + return proxy.request(Object.assign({ method: 'head', url: url }, transData(req))) }, - delete(url: string, req: data): Promise { - return proxy.request({ method: 'delete', url: url, headers: req.headers, data: req.req, params: req.params }) + Delete(url: string, req: data): Promise { + return proxy.request(Object.assign({ method: 'delete', url: url }, transData(req))) }, - post(url: string, req: data): Promise { - return proxy.request({ method: 'post', url: url, headers: req.headers, data: req.req, params: req.params }) + Post(url: string, req: data): Promise { + return proxy.request(Object.assign({ method: 'post', url: url }, transData(req))) }, - put(url: string, req: data): Promise { - return proxy.request({ method: 'put', url: url, headers: req.headers, data: req.req, params: req.params }) + Put(url: string, req: data): Promise { + return proxy.request(Object.assign({ method: 'put', url: url }, transData(req))) }, - patch(url: string, req: data): Promise { - return proxy.request({ method: 'patch', url: url, headers: req.headers, data: req.req, params: req.params }) + Patch(url: string, req: data): Promise { + return proxy.request(Object.assign({ method: 'patch', url: url }, transData(req))) }, } - export default webapi - - diff --git a/oaweb/composables/index.ts b/oaweb/composables/index.ts index c95f37e..83c128f 100644 --- a/oaweb/composables/index.ts +++ b/oaweb/composables/index.ts @@ -6,7 +6,6 @@ */ import api from './api' - export * from './models' export { type Auths, type modelsSimpleAuth } from './models' export { api } diff --git a/oaweb/nuxt.config.ts b/oaweb/nuxt.config.ts index 3809472..ba69c98 100644 --- a/oaweb/nuxt.config.ts +++ b/oaweb/nuxt.config.ts @@ -4,7 +4,14 @@ export default defineNuxtConfig({ css: [ '~/assets/css/app.scss', + '~/assets/css/tailwind.css', ], + postcss: { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, + }, ssr: false, @@ -46,5 +53,5 @@ export default defineNuxtConfig({ ] }, }, - modules: ["@pinia/nuxt", "@nuxt/ui"] + modules: ["@pinia/nuxt"] })