From 3fb1e16f80ee8c097360d08ac7dd0776a2388591 Mon Sep 17 00:00:00 2001 From: veypi Date: Fri, 20 Sep 2024 16:03:11 +0800 Subject: [PATCH] update --- README.md | 5 + oa/Makefile | 9 +- oa/internal/handler/app/loginhandler.go | 5 +- oa/internal/handler/routes.go | 2 +- oa/internal/logic/app/loginlogic.go | 1 - oa/internal/logic/user/loginlogic.go | 2 + oa/internal/types/types.go | 9 +- oa/protoc/api/app.api | 5 +- oa/protoc/api/user.api | 6 +- oab/src/libs/auth.rs | 1 - oab/src/libs/mod.rs | 1 - oab/src/libs/proxy.rs | 6 -- oaer/lib/assets/css/oaer.scss | 111 ---------------------- oaer/lib/main.ts | 6 +- oaer/src/main.ts | 2 +- oaweb/composables/api/access.ts | 30 ------ oaweb/composables/api/app.ts | 56 ++--------- oaweb/composables/api/axios.ts | 86 ----------------- oaweb/composables/api/gocliRequest.ts | 119 ++++++++++++++++++++++++ oaweb/composables/api/index.ts | 30 ++---- oaweb/composables/api/mainComponents.ts | 47 ++++++++++ oaweb/composables/api/nats.ts | 19 ---- oaweb/composables/api/resource.ts | 30 ------ oaweb/composables/api/role.ts | 36 ------- oaweb/composables/api/token.ts | 18 ---- oaweb/composables/api/tsdb.ts | 25 ----- oaweb/composables/api/user.ts | 69 ++++++-------- oaweb/nuxt.config.ts | 8 +- oaweb/pages/login.vue | 10 +- 29 files changed, 248 insertions(+), 506 deletions(-) delete mode 100644 oab/src/libs/proxy.rs delete mode 100644 oaweb/composables/api/access.ts delete mode 100644 oaweb/composables/api/axios.ts create mode 100644 oaweb/composables/api/gocliRequest.ts create mode 100644 oaweb/composables/api/mainComponents.ts delete mode 100644 oaweb/composables/api/nats.ts delete mode 100644 oaweb/composables/api/resource.ts delete mode 100644 oaweb/composables/api/role.ts delete mode 100644 oaweb/composables/api/token.ts delete mode 100644 oaweb/composables/api/tsdb.ts diff --git a/README.md b/README.md index 29cbcae..79f248d 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,11 @@ [Demo](https://oa.veypi.com) +## Auth + +code用来兑换本身应用token和兑换其他应用付出权限token +oa code 可以用来生成其他code和刷新本身code + ### 依赖库 diff --git a/oa/Makefile b/oa/Makefile index d1aac18..9e2f9f4 100644 --- a/oa/Makefile +++ b/oa/Makefile @@ -30,18 +30,13 @@ gen_db: @sqlx database create -D $(db) @sqlx migrate --source ./protoc/sql run -D $(db) -gen_api: +gen_api: fmt @goctl api format --dir ./protoc/api/ @goctl api go -api ./protoc/api/all.api -dir ./ ts_dir= ../oaweb/composables/api/ -gen_ts: - @goctl api ts -api ./protoc/api/user.api -dir $(ts_dir) - @mv $(ts_dir)/main.ts $(ts_dir)/user.ts - @goctl api ts -api ./protoc/api/app.api -dir $(ts_dir) - @mv $(ts_dir)/main.ts $(ts_dir)/app.ts +gen_ts: fmt @goctl api ts -api ./protoc/api/all.api -dir $(ts_dir) - @rm $(ts_dir)/main.ts run: @go run main.go -f ./etc/main.yaml diff --git a/oa/internal/handler/app/loginhandler.go b/oa/internal/handler/app/loginhandler.go index 7510597..811bf25 100644 --- a/oa/internal/handler/app/loginhandler.go +++ b/oa/internal/handler/app/loginhandler.go @@ -1,14 +1,16 @@ package app import ( + "fmt" "net/http" "oa/errs" - "github.com/zeromicro/go-zero/rest/httpx" "oa/internal/logic/app" "oa/internal/svc" "oa/internal/types" + + "github.com/zeromicro/go-zero/rest/httpx" ) func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -18,6 +20,7 @@ func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { errs.Response(w, nil, err) return } + fmt.Printf("\n|%v|\n", req) l := app.NewLoginLogic(r.Context(), svcCtx) resp, err := l.Login(&req) diff --git a/oa/internal/handler/routes.go b/oa/internal/handler/routes.go index ce91a7f..3fe359d 100644 --- a/oa/internal/handler/routes.go +++ b/oa/internal/handler/routes.go @@ -15,7 +15,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ { - Method: http.MethodPost, + Method: http.MethodGet, Path: "/login/:pa", Handler: app.LoginHandler(serverCtx), }, diff --git a/oa/internal/logic/app/loginlogic.go b/oa/internal/logic/app/loginlogic.go index 65f932d..5c61b03 100644 --- a/oa/internal/logic/app/loginlogic.go +++ b/oa/internal/logic/app/loginlogic.go @@ -25,6 +25,5 @@ func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic func (l *LoginLogic) Login(req *types.AppReq) (resp *types.AppResp, err error) { // todo: add your logic here and delete this line - return } diff --git a/oa/internal/logic/user/loginlogic.go b/oa/internal/logic/user/loginlogic.go index d836fec..ff691dd 100644 --- a/oa/internal/logic/user/loginlogic.go +++ b/oa/internal/logic/user/loginlogic.go @@ -3,6 +3,7 @@ package user import ( "context" "database/sql" + "fmt" "strings" "time" @@ -33,6 +34,7 @@ func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic func (l *LoginLogic) Login(req *types.LoginReq) (string, error) { // todo: add your logic here and delete this line m := models.NewUserModel(l.svcCtx.Sqlx()) + fmt.Printf("\n|%v|\n", req) var u *models.User var err error switch req.Typ { diff --git a/oa/internal/types/types.go b/oa/internal/types/types.go index d5e9349..9bece2f 100644 --- a/oa/internal/types/types.go +++ b/oa/internal/types/types.go @@ -2,9 +2,8 @@ package types type AppReq struct { - Appname string `json:"username"` + Appname string `form:"username"` Password string `json:"password"` - Pas string `query:"pas"` Pa string `path:"pa"` } @@ -17,9 +16,9 @@ type AppResp struct { type LoginReq struct { Id string `path:"id"` - Client string `json:"client"` - Pwd string `json:"pwd"` - Typ string `json:"typ,optional"` + Pwd string `form:"pwd"` + Client string `form:"client"` + Typ string `form:"typ,optional"` } type RegReq struct { diff --git a/oa/protoc/api/app.api b/oa/protoc/api/app.api index 56ca55f..6b31f64 100644 --- a/oa/protoc/api/app.api +++ b/oa/protoc/api/app.api @@ -3,9 +3,8 @@ import "base.api" type ( // 定义登录接口的请求体 AppReq { - appname string `json:"username"` + appname string `form:"username"` Password string `json:"password"` - Pas string `query:"pas"` Pa string `path:"pa"` } // 定义登录接口的响应体 @@ -33,6 +32,6 @@ service main { // 路由为 /app/login // 请求体为 LoginReq // 响应体为 LoginResp,响应体必须有 returns 关键字修饰 - post /login/:pa (AppReq) returns (AppResp) + get /login/:pa (AppReq) returns (AppResp) } diff --git a/oa/protoc/api/user.api b/oa/protoc/api/user.api index 8444ef2..873fd31 100644 --- a/oa/protoc/api/user.api +++ b/oa/protoc/api/user.api @@ -3,9 +3,9 @@ import "base.api" type ( LoginReq { id string `path:"id"` - client string `json:"client"` - pwd string `json:"pwd"` - typ string `json:"typ,optional"` + pwd string `form:"pwd"` + client string `form:"client"` + typ string `form:"typ,optional"` } RegReq { username string `json:"username"` diff --git a/oab/src/libs/auth.rs b/oab/src/libs/auth.rs index b5d2ab7..b26ad4a 100644 --- a/oab/src/libs/auth.rs +++ b/oab/src/libs/auth.rs @@ -6,7 +6,6 @@ // use std::cell::RefCell; -use std::fmt; use std::pin::Pin; use std::rc::Rc; use std::task::{Context, Poll}; diff --git a/oab/src/libs/mod.rs b/oab/src/libs/mod.rs index a61e5ec..4d63aac 100644 --- a/oab/src/libs/mod.rs +++ b/oab/src/libs/mod.rs @@ -9,6 +9,5 @@ pub mod app; pub mod appfs; pub mod auth; pub mod cors; -pub mod proxy; pub mod task; pub mod user; diff --git a/oab/src/libs/proxy.rs b/oab/src/libs/proxy.rs deleted file mode 100644 index a219043..0000000 --- a/oab/src/libs/proxy.rs +++ /dev/null @@ -1,6 +0,0 @@ -// -// proxy.rs -// Copyright (C) 2023 veypi -// 2023-10-19 19:31 -// Distributed under terms of the MIT license. -// diff --git a/oaer/lib/assets/css/oaer.scss b/oaer/lib/assets/css/oaer.scss index c6a3e59..93d2e2b 100644 --- a/oaer/lib/assets/css/oaer.scss +++ b/oaer/lib/assets/css/oaer.scss @@ -81,117 +81,6 @@ backdrop-filter: blur(20px); /* 模糊效果 */ z-index: -1; } - .header { - line-height: 2rem; - width: 100%; - display: flex; - justify-content: start; - align-items: center; - gap: 0.5rem; - .voa-logo { - height: 4rem; - width: 4rem; - } - .txt { - font-size: 1.5rem; - } - } - .username, - .password { - margin: 2rem 0; - position: relative; - width: 100%; - input { - height: 2.5rem; - line-height: 2.5rem; - font-size: 1.5rem; - width: 100%; - margin: 0 1rem; - border: none; - outline: none; - background: none; - } - &:after { - content: ""; - position: absolute; - bottom: 0; - left: 1rem; - width: calc(100% - 2rem); - height: 0.1em; - background-color: #000; - transition: all 0.3s; - } - &:hover::after { - left: 0%; - width: 100%; - background-color: #00ffff; - } - } - .ok { - cursor: pointer; - line-height: 3rem; - font-size: 1.5rem; - height: 3rem; - margin: 2rem auto; - width: 40%; - background: #0a0; - border-radius: 1.5rem; - } - .last { - display: flex; - justify-content: space-between; - padding: 0 1rem; - height: 3rem; - .icos { - display: flex; - align-items: center; - gap: 1rem; - div { - opacity: 0.5; - cursor: pointer; - height: 2rem; - width: 2rem; - background-size: cover; - background-position: center; - &:hover { - opacity: 1; - } - } - .github { - background-image: url("../img/github.svg"); - } - .google { - background-image: url("../img/google.svg"); - } - .wechat { - background-image: url("../img/wechat.svg"); - } - } - .txt { - height: 1.5rem; - line-height: 1.5rem; - font-size: 1rem; - div { - cursor: pointer; - opacity: 0.5; - &:hover { - opacity: 1; - } - } - } - } - .close { - height: 2rem; - width: 2rem; - position: absolute; - opacity: 0.5; - top: 1rem; - right: 1rem; - cursor: pointer; - &:active { - opacity: 0.8; - } - } } #voa-mask { diff --git a/oaer/lib/main.ts b/oaer/lib/main.ts index e135950..13a73d7 100644 --- a/oaer/lib/main.ts +++ b/oaer/lib/main.ts @@ -9,8 +9,9 @@ import './assets/css/oaer.scss' export class OAer { - domid: string id: string + code: string + domid: string dom: { mask: HTMLDivElement frame: HTMLDivElement @@ -18,8 +19,9 @@ export class OAer { b1?: HTMLDivElement login_box?: HTMLDivElement } - constructor(id: string, domid?: string) { + constructor(id: string, code: string, domid?: string) { this.id = id + this.code = code this.domid = domid || 'oaer' this.dom = { frame: document.querySelector(`#${this.domid}`)!, diff --git a/oaer/src/main.ts b/oaer/src/main.ts index e866a30..138854c 100644 --- a/oaer/src/main.ts +++ b/oaer/src/main.ts @@ -1,6 +1,6 @@ import './style.css' import { OAer } from '../lib/main' -let t = new OAer('123') +let t = new OAer('123', '') console.log(t.domid) diff --git a/oaweb/composables/api/access.ts b/oaweb/composables/api/access.ts deleted file mode 100644 index ab0a777..0000000 --- a/oaweb/composables/api/access.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * access.ts - * Copyright (C) 2023 veypi - * 2023-10-12 19:32 - * Distributed under terms of the MIT license. - */ - - -import ajax from './axios' - -export default (app_id: string) => { - return { - local: `./app/${app_id}/access/`, - create(name: string, props?: { name?: string, level?: number, role_id?: string, user_id?: string, rid?: string }) { - return ajax.post(this.local, Object.assign({ name, level: 0 }, props)) - }, - get(id: string) { - return ajax.get(this.local + id) - }, - list(props?: { name?: string, role_id?: string, user_id?: string }) { - return ajax.get(this.local, props) - }, - update(uuid: string, props: any) { - return ajax.patch(this.local + uuid, props) - }, - del(id: string) { - return ajax.delete(this.local + id) - }, - } -} diff --git a/oaweb/composables/api/app.ts b/oaweb/composables/api/app.ts index 128097b..3c134c6 100644 --- a/oaweb/composables/api/app.ts +++ b/oaweb/composables/api/app.ts @@ -1,48 +1,12 @@ -/* - * app.ts - * Copyright (C) 2023 veypi - * 2023-09-30 17:31 - * Distributed under terms of the MIT license. - */ - +import webapi from "./gocliRequest" +import * as components from "./mainComponents" +export * from "./mainComponents" -import ajax from './axios' - -export default { - local: './app/', - self() { - return ajax.get(this.local, { option: 'oa' }) - }, - getKey(uuid: string) { - return ajax.get(this.local + uuid + '/key') - }, - create(name: string, icon: string) { - return ajax.post(this.local, { name, icon }) - }, - get(uuid: string) { - return ajax.get(this.local + uuid) - }, - list() { - return ajax.get(this.local) - }, - update(uuid: string, props: any) { - return ajax.patch(this.local + uuid, props) - }, - user(uuid: string) { - if (uuid === '') { - uuid = '-' - } - return { - local: this.local + uuid + '/user/', - list(id: string, data?: any) { - return ajax.get(this.local + id, data) - }, - add(uid: string) { - return ajax.post(this.local + uid) - }, - update(uid: string, status: number) { - return ajax.patch(this.local + uid, { status }) - }, - } - }, +/** + * @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}) } diff --git a/oaweb/composables/api/axios.ts b/oaweb/composables/api/axios.ts deleted file mode 100644 index 8839df3..0000000 --- a/oaweb/composables/api/axios.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* - * axios.ts - * Copyright (C) 2023 veypi - * 2023-09-22 20:22 - * Distributed under terms of the MIT license. - */ - -import axios, { AxiosError, AxiosResponse } from 'axios'; - -// Be careful when using SSR for cross-request state pollution -// due to creating a Singleton instance here; -// If any client changes this (global) instance, it might be a -// good idea to move this instance creation inside of the -// "export default () => {}" function below (which runs individually -// for each client) - -const proxy = axios.create({ - baseURL: '/api/', - withCredentials: true, - headers: { - 'content-type': 'application/json;charset=UTF-8', - }, -}); - - -// 请求拦截 -const beforeRequest = (config: any) => { - // 设置 token - const token = util.getToken() - // // NOTE 添加自定义头部 - token && (config.headers.auth_token = token) - // config.headers['auth_token'] = '' - return config -} -proxy.interceptors.request.use(beforeRequest) - -// 响应拦截器 -const responseSuccess = (response: AxiosResponse) => { - // eslint-disable-next-line yoda - // 这里没有必要进行判断,axios 内部已经判断 - // const isOk = 200 <= response.status && response.status < 300 - let data = response.data - if (response.config.method === 'head') { - data = JSON.parse(JSON.stringify(response.headers)) - } - return Promise.resolve(data) -} - -const responseFailed = (error: AxiosError) => { - const { response } = error - if (!window.navigator.onLine) { - - alert('没有网络') - return Promise.reject(new Error('请检查网络连接')) - } - console.warn(response) - return Promise.reject(response?.data || response?.headers.error) -} - -proxy.interceptors.response.use(responseSuccess, responseFailed) - - -const ajax = { - get(url: string, data = {}, header?: any) { - return proxy.get(url, { params: data, headers: header }) - }, - head(url: string, data = {}, header?: any) { - return proxy.head(url, { params: data, headers: header }) - }, - delete(url: string, data = {}, header?: any) { - return proxy.delete(url, { params: data, headers: header }) - }, - - post(url: string, data = {}, header?: any) { - return proxy.post(url, data, { headers: header }) - }, - put(url: string, data = {}, header?: any) { - return proxy.put(url, data, { headers: header }) - }, - patch(url: string, data = {}, header?: any) { - return proxy.patch(url, data, { headers: header }) - }, -} - -export default ajax - diff --git a/oaweb/composables/api/gocliRequest.ts b/oaweb/composables/api/gocliRequest.ts new file mode 100644 index 0000000..82bc1fc --- /dev/null +++ b/oaweb/composables/api/gocliRequest.ts @@ -0,0 +1,119 @@ +/* + * gocliRequest.ts + * Copyright (C) 2024 veypi + * 2024-08-02 17:14 + * Distributed under terms of the MIT license. + */ + + +import axios, { AxiosError, type AxiosResponse } from 'axios'; + +// Be careful when using SSR for cross-request state pollution +// due to creating a Singleton instance here; +// If any client changes this (global) instance, it might be a +// good idea to move this instance creation inside of the +// "export default () => {}" function below (which runs individually +// for each client) + +axios.defaults.withCredentials = true +const proxy = axios.create({ + withCredentials: true, + headers: { + 'content-type': 'application/json;charset=UTF-8', + }, +}); + + +// 请求拦截 +const beforeRequest = (config: any) => { + // 设置 token + const token = util.getToken() + config.retryTimes = 3 + // NOTE 添加自定义头部 + token && (config.headers.Authorization = `Bearer ${token}`) + // config.headers['auth_token'] = '' + return config +} +proxy.interceptors.request.use(beforeRequest) + +// 响应拦截器 +const responseSuccess = (response: AxiosResponse) => { + // eslint-disable-next-line yoda + // 这里没有必要进行判断,axios 内部已经判断 + // const isOk = 200 <= response.status && response.status < 300 + let data = response.data + return Promise.resolve(data) +} + +const responseFailed = (error: AxiosError) => { + const { response, config } = error + if (!window.navigator.onLine) { + + alert('没有网络') + return Promise.reject(new Error('请检查网络连接')) + } + + console.log(response) + let needRetry = false + if (!needRetry) { + return Promise.reject(response?.data || response?.headers.error) + }; + // @ts-ignore + const { __retryCount = 0, retryDelay = 1000, retryTimes } = config; + // 在请求对象上设置重试次数 + // @ts-ignore + config.__retryCount = __retryCount; + // 判断是否超过了重试次数 + if (__retryCount >= retryTimes) { + return Promise.reject(response?.data || response?.headers.error) + } + // 增加重试次数 + // @ts-ignore + config.__retryCount++; + // 延时处理 + const delay = new Promise((resolve) => { + setTimeout(() => { + resolve(); + }, retryDelay); + }); + // 重新发起请求 + return delay.then(function() { + return proxy.request(config as any); + }); +} + +proxy.interceptors.response.use(responseSuccess, responseFailed) + + +interface data { + params?: any + req?: any + headers?: any +} + +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 }) + }, + head(url: string, req: data): Promise { + return proxy.request({ method: 'head', url: url, headers: req.headers, data: req.req, params: req.params }) + }, + delete(url: string, req: data): Promise { + return proxy.request({ method: 'delete', url: url, headers: req.headers, data: req.req, params: req.params }) + }, + + post(url: string, req: data): Promise { + return proxy.request({ method: 'post', url: url, headers: req.headers, data: req.req, params: req.params }) + }, + put(url: string, req: data): Promise { + return proxy.request({ method: 'put', url: url, headers: req.headers, data: req.req, params: req.params }) + }, + patch(url: string, req: data): Promise { + return proxy.request({ method: 'patch', url: url, headers: req.headers, data: req.req, params: req.params }) + }, +} + + +export default webapi + + diff --git a/oaweb/composables/api/index.ts b/oaweb/composables/api/index.ts index e05dd20..e9bebf2 100644 --- a/oaweb/composables/api/index.ts +++ b/oaweb/composables/api/index.ts @@ -1,32 +1,14 @@ /* * index.ts - * Copyright (C) 2023 veypi - * 2023-09-22 20:17 + * Copyright (C) 2024 veypi + * 2024-08-02 17:40 * Distributed under terms of the MIT license. */ -import app from "./app"; -import role from "./role"; -import token from "./token"; -import user from "./user"; -import resource from "./resource"; -import access from './access'; -import nats from './nats' -import tsdb from './tsdb' +import * as user from './user' +import * as app from './app' - - -const api = { +export default { user, - app, - token, - role, - resource, - access, - tsdb, - nats + app } - - -export default api; - diff --git a/oaweb/composables/api/mainComponents.ts b/oaweb/composables/api/mainComponents.ts new file mode 100644 index 0000000..b4926c0 --- /dev/null +++ b/oaweb/composables/api/mainComponents.ts @@ -0,0 +1,47 @@ +// 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/nats.ts b/oaweb/composables/api/nats.ts deleted file mode 100644 index 3ea4c08..0000000 --- a/oaweb/composables/api/nats.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * nats.ts - * Copyright (C) 2023 veypi - * 2023-10-19 21:36 - * Distributed under terms of the MIT license. - */ - - -import ajax from './axios' - -export default { - local: './nats/', - general() { - return ajax.get(this.local + 'varz') - }, - conns() { - return ajax.get(this.local + 'connz', { subs: true }) - }, -} diff --git a/oaweb/composables/api/resource.ts b/oaweb/composables/api/resource.ts deleted file mode 100644 index 39c00fd..0000000 --- a/oaweb/composables/api/resource.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * resource.ts - * Copyright (C) 2023 veypi - * 2023-10-12 18:03 - * Distributed under terms of the MIT license. - */ - - -import ajax from './axios' - -export default (app_id: string) => { - return { - local: `./app/${app_id}/resource/`, - create(name: string, props?: { des?: string }) { - return ajax.post(this.local, Object.assign({ name }, props)) - }, - get(id: string) { - return ajax.get(this.local + id) - }, - list() { - return ajax.get(this.local) - }, - update(uuid: string, props: any) { - return ajax.patch(this.local + uuid, props) - }, - del(id: string) { - return ajax.delete(this.local + id) - }, - } -} diff --git a/oaweb/composables/api/role.ts b/oaweb/composables/api/role.ts deleted file mode 100644 index 583ab10..0000000 --- a/oaweb/composables/api/role.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * role.ts - * Copyright (C) 2023 veypi - * 2023-10-12 15:40 - * Distributed under terms of the MIT license. - */ - - -import ajax from './axios' - -export default (app_id: string) => { - return { - local: `./app/${app_id}/role/`, - create(name: string, props?: { des?: string }) { - return ajax.post(this.local, Object.assign({ name }, props)) - }, - get(id: string) { - return ajax.get(this.local + id) - }, - list() { - return ajax.get(this.local) - }, - update(uuid: string, props: any) { - return ajax.patch(this.local + uuid, props) - }, - del(id: string) { - return ajax.delete(this.local + id) - }, - add(id: string, uid: string) { - return ajax.get(this.local + `${id}/user/${uid}`) - }, - drop(id: string, uid: string) { - return ajax.delete(this.local + `${id}/user/${uid}`) - } - } -} diff --git a/oaweb/composables/api/token.ts b/oaweb/composables/api/token.ts deleted file mode 100644 index 74efca9..0000000 --- a/oaweb/composables/api/token.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * token.ts - * Copyright (C) 2023 veypi - * 2023-09-30 17:37 - * Distributed under terms of the MIT license. - */ - - -import ajax from './axios' - -export default (uuid: string) => { - return { - local: './app/' + uuid + '/token/', - get(data: { app_id?: string, token: string }) { - return ajax.post(this.local, data) - }, - } -} diff --git a/oaweb/composables/api/tsdb.ts b/oaweb/composables/api/tsdb.ts deleted file mode 100644 index 799c047..0000000 --- a/oaweb/composables/api/tsdb.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * tsdb.ts - * Copyright (C) 2023 veypi - * 2023-10-20 23:21 - * Distributed under terms of the MIT license. - */ - - -import ajax from './axios' - -export default { - local: './ts/', - range(query: string, props?: { start?: string, end?: string, step?: string, query?: string }) { - if (query !== undefined) { - // @ts-ignore - props.query = query - } else { - props = { query: query } - } - return ajax.get(this.local + 'query_range', props) - }, - query(query: string) { - return ajax.get(this.local + 'query', { query: query }) - } -} diff --git a/oaweb/composables/api/user.ts b/oaweb/composables/api/user.ts index 2b46a61..bfb06d4 100644 --- a/oaweb/composables/api/user.ts +++ b/oaweb/composables/api/user.ts @@ -1,48 +1,33 @@ +import webapi from "./gocliRequest" +import * as components from "./mainComponents" +export * from "./mainComponents" -/* - * user.ts - * Copyright (C) 2023 veypi - * 2023-09-22 20:18 - * Distributed under terms of the MIT license. +/** + * @description + * @param req */ +export function reg(req: components.RegReq) { + return webapi.post(`/api/user`, {"req":req}) +} +/** + * @description + * @param params + */ +export function login(id: string, params: components.LoginReqParams) { + return webapi.head(`/api/user/${id}`, {"params":params}) +} -import { Base64 } from 'js-base64' -import ajax from './axios' - -export default { - local: './user/', - register(username: string, password: string, prop?: any) { - const data = Object.assign({ - username: username, - password: Base64.encode(password), - }, prop) - return ajax.post(this.local, data) - }, - reset(id: string, p?: string) { - if (p) { - p = Base64.encode(p) - } - return ajax.get(this.local + id + '/reset', { p: p }) - }, - login(username: string, password: string) { - return ajax.head(this.local + username, { - typ: 'username', - password: Base64.encode(password), - }) - }, - search(q: string) { - return ajax.get(this.local, { username: q }) - }, - get(id: number) { - return ajax.get(this.local + id) - }, - list(props?: { name?: string, role_id?: string, app_id?: string }) { - return ajax.get(this.local, props) - }, - update(id: string, props: any) { - props.test = { a: 1 } - return ajax.patch(this.local + id, props) - }, +/** + * @description + */ +export function list() { + return webapi.get>(`/api/user`, {}) } +/** + * @description + */ +export function get(id: number) { + return webapi.get(`/api/user/${id}`, {}) +} diff --git a/oaweb/nuxt.config.ts b/oaweb/nuxt.config.ts index 29279a9..3809472 100644 --- a/oaweb/nuxt.config.ts +++ b/oaweb/nuxt.config.ts @@ -11,17 +11,17 @@ export default defineNuxtConfig({ nitro: { devProxy: { "/api": { - target: "http://127.0.0.1:4001/api", + target: "http://127.0.0.1:4000/api", changeOrigin: true, ws: true, }, '/fs': { - target: 'http://127.0.0.1:4001/fs', + target: 'http://127.0.0.1:4000/fs', changeOrigin: true, ws: true, }, '/media': { - target: 'http://127.0.0.1:4001/media', + target: 'http://127.0.0.1:4000/media', changeOrigin: true, ws: true, }, @@ -47,4 +47,4 @@ export default defineNuxtConfig({ }, }, modules: ["@pinia/nuxt", "@nuxt/ui"] -}) \ No newline at end of file +}) diff --git a/oaweb/pages/login.vue b/oaweb/pages/login.vue index 6b103ce..252ba9d 100644 --- a/oaweb/pages/login.vue +++ b/oaweb/pages/login.vue @@ -88,6 +88,7 @@