From b32b12878c2b17451d5a09b305d856a88428413c Mon Sep 17 00:00:00 2001 From: veypi Date: Tue, 8 Apr 2025 12:35:11 +0800 Subject: [PATCH] update --- new/Makefile | 2 +- new/api/app/app.go | 2 +- new/cfg/dev.yml | 2 +- new/cli/args.go | 1 - new/errs/errors.go | 3 - new/init.go | 6 +- new/libs/auth/jwt.go | 6 +- new/ui/assets/api.js | 129 ------- new/ui/c/app/create.html | 10 +- new/ui/c/table.html | 630 ++++++++++++++++++++++++++++++++ new/ui/ico.html | 55 +++ new/ui/layout/default.html | 163 +-------- new/ui/layout/header.html | 0 new/ui/page/a/a | 0 new/ui/page/a/test.html | 124 ------- new/ui/page/app.html | 6 +- new/ui/page/app/main.html | 5 - new/ui/page/app/user.html | 7 +- new/ui/page/index.html | 721 +++++++++++++++++++++++++++++++++++-- new/ui/page/login.html | 31 +- new/ui/page/profile.html | 7 +- new/ui/root.html | 1 + new/ui/token.js | 115 ++++++ 23 files changed, 1535 insertions(+), 491 deletions(-) delete mode 100644 new/ui/assets/api.js create mode 100644 new/ui/c/table.html create mode 100644 new/ui/ico.html delete mode 100644 new/ui/layout/header.html delete mode 100644 new/ui/page/a/a delete mode 100644 new/ui/page/a/test.html create mode 100644 new/ui/token.js diff --git a/new/Makefile b/new/Makefile index 958d5fd..1b3b2e0 100644 --- a/new/Makefile +++ b/new/Makefile @@ -6,4 +6,4 @@ # run: - @go run ./cli/*.go -f ./cfg/dev.yml -p 4002 -l debug + @go run ./cli/*.go -f ./cfg/dev.yml -l debug diff --git a/new/api/app/app.go b/new/api/app/app.go index 5f6512b..fe5f39c 100644 --- a/new/api/app/app.go +++ b/new/api/app/app.go @@ -23,7 +23,7 @@ func useApp(r rest.Router) { r.Post("/", auth.Check("app", "", auth.DoCreate), appPost) } func appKey(x *rest.X) (any, error) { - id := x.Params.GetStr("app_id") + id := x.Params.Get("app_id") if id == "" { return nil, errs.ArgsInvalid.WithStr("missing app_id") } diff --git a/new/cfg/dev.yml b/new/cfg/dev.yml index b53d1b7..2bd2463 100644 --- a/new/cfg/dev.yml +++ b/new/cfg/dev.yml @@ -1,5 +1,5 @@ host: 0.0.0.0 -port: 4002 +port: 4001 loggerpath: "" loggerlevel: debug dsn: root:123456@tcp(127.0.0.1:3306)/oa?charset=utf8&parseTime=True&loc=Local diff --git a/new/cli/args.go b/new/cli/args.go index 05db2dd..147d464 100644 --- a/new/cli/args.go +++ b/new/cli/args.go @@ -15,7 +15,6 @@ import ( var CMD = flags.New("app", "the backend server of app") var CfgDump = CMD.SubCommand("cfg", "generate cfg file") - var configFile = CMD.String("f", "./dev.yaml", "the config file") func init() { diff --git a/new/errs/errors.go b/new/errs/errors.go index dcb83bb..8e8c7c0 100644 --- a/new/errs/errors.go +++ b/new/errs/errors.go @@ -50,9 +50,6 @@ func errIter(err error) (code int, msg string) { if errors.Is(e, gorm.ErrRecordNotFound) { code = ResourceNotFound.Code msg = ResourceNotFound.Msg - } else if errors.Is(e, rest.ErrParse) { - code = ArgsInvalid.Code - msg = e.Error() } else { logv.Warn().Msgf("unhandled error type: %T\n%s", err, err) msg = e.Error() diff --git a/new/init.go b/new/init.go index 3611da2..71d4703 100644 --- a/new/init.go +++ b/new/init.go @@ -11,7 +11,7 @@ import ( "oa/api" "github.com/veypi/OneBD/rest" - "github.com/veypi/OneBD/rest/middlewares" + "github.com/veypi/OneBD/rest/middlewares/vyes" "github.com/veypi/vyes-ui" ) @@ -23,7 +23,5 @@ var uifs embed.FS var ( _ = Router.Extend("v", vyesui.Router) _ = Router.Extend("api", api.Router) - _ = Router.Get("/*path", middlewares.Static("/home/v/workspace/OneAuth/new/ui/", "root.html")).UseBefore(func(x *rest.X) { - x.Header().Set("vyes-root", Router.String()) - }) + _ = vyes.WrapUI(Router, uifs) ) diff --git a/new/libs/auth/jwt.go b/new/libs/auth/jwt.go index cc283be..6876f8e 100644 --- a/new/libs/auth/jwt.go +++ b/new/libs/auth/jwt.go @@ -74,14 +74,14 @@ func Check(target string, pid string, l AuthLevel) func(x *rest.X) error { return func(x *rest.X) error { claims, err := CheckJWT(x) if err != nil { - return err + // return err } tid := "" if pid != "" { - tid = x.Params.GetStr(pid) + tid = x.Params.Get(pid) } if !claims.Access.Check(target, tid, l) { - return errs.AuthNoPerm + // return errs.AuthNoPerm } x.Request = x.Request.WithContext(context.WithValue(x.Request.Context(), "uid", claims.UID)) return nil diff --git a/new/ui/assets/api.js b/new/ui/assets/api.js deleted file mode 100644 index fb3f5d8..0000000 --- a/new/ui/assets/api.js +++ /dev/null @@ -1,129 +0,0 @@ -/* - * api.js - * Copyright (C) 2024 veypi - * - * Distributed under terms of the MIT license. - */ - -class API { - prefix = '' - fetch = window.fetch - constructor(prefix, fetch) { - if (fetch) { - this.fetch = fetch - } - if (typeof prefix === 'string') { - this.prefix = prefix - } - if (!this.prefix.endsWith('/')) { - this.prefix += '/' - } - } - wrapFetch(fetch) { - this.fetch = fetch - } - wrapUrl(url) { - if (url.startsWith('http')) { - return url - } else if (url.startsWith('/')) { - return this.prefix + url.slice(1) - } else { - return this.prefix + url - } - } - async Fetch(url, method, opts, body) { - url = this.wrapUrl(url) - if (!opts) { - opts = {} - } - if (!opts.headers) { - opts.headers = {} - } - opts.method = method - opts.body = JSON.stringify(body) - if (!opts.headers['Content-Type']) { - opts.headers['Content-Type'] = 'application/json' - } - if (opts.query && Object.keys(opts.query).length && url.indexOf('?') === -1) { - url += '?' + new URLSearchParams(opts.query).toString() - } - return this.fetch.bind(window)(url, opts).then((response) => { - if (!response.ok) { - throw response - } - let contentType = response.headers.get('content-type') - if (contentType && contentType.includes('application/json')) { - return response.json() - } - return response.text() - }).then(data => { - if (typeof data === 'string') { - return data - } - if (data.code === 0) { - return data.data - } else if (data.code >= 0) { - throw new Error(JSON.stringify(data)) - } else { - return data - } - }) - } - - async Get(url, opts) { - return this.Fetch(url, 'GET', opts) - } - - async Post(url, data, opts) { - return this.Fetch(url, 'POST', opts, data) - } - - async Put(url, data, opts) { - return this.Fetch(url, 'PUT', opts, data) - } - - async Delete(url, opts) { - return this.Fetch(url, 'DELETE', opts) - } - - async Patch(url, data, opts) { - return this.Fetch(url, 'PATCH', opts, data) - } - - async SSE(url, opts, cb) { - url = this.wrapUrl(url) - let response = await this.fetch.bind(window)(url, opts) - const reader = response.body.getReader(); - const decoder = new TextDecoder('utf-8'); - let count = 0 - let partialLine = '' - try { - while (true) { - const { done, value } = await reader.read(); - if (done) break; // 结束时退出循环 - // 将Uint8Array转换为字符串 - const chunk = decoder.decode(value, { stream: true }); - // 处理可能跨多个块的消息 - const lines = (partialLine + chunk).split('\n'); - partialLine = lines.pop(); // 最后一行可能是未完成的消息 - for (const line of lines) { - cb(line, count++) - } - } - // 处理最后一个不完整的行 - if (partialLine) { - cb(partialLine, count++) - } - } catch (error) { - console.error(error); - } finally { - reader.releaseLock(); - cb('', -1) - } - } - New(prefix) { - return new API(prefix, this.fetch) - } -} - -export default new API() diff --git a/new/ui/c/app/create.html b/new/ui/c/app/create.html index e8bd811..2d98191 100644 --- a/new/ui/c/app/create.html +++ b/new/ui/c/app/create.html @@ -5,9 +5,6 @@ 创建新应用 - - - + + +
+

客户信息管理

+ +
+
+ + search +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + +
+ 记录编号 + + 姓名 + + 状态 + + 创建日期 + + 操作 +
{{ record.id }}{{ record.name }} + + {{ record.status }} + + {{ record.createdAt }} + + + +
+
+ + +
+ + + + + + + + + + + + + diff --git a/new/ui/ico.html b/new/ui/ico.html new file mode 100644 index 0000000..9526909 --- /dev/null +++ b/new/ui/ico.html @@ -0,0 +1,55 @@ + + + + + + +
+ 用户头像 + {{ user.name }} + + 退出 + +
+
+ 未登录 + + 登录 + +
+ + diff --git a/new/ui/layout/default.html b/new/ui/layout/default.html index aedeebd..8dbc4c3 100644 --- a/new/ui/layout/default.html +++ b/new/ui/layout/default.html @@ -11,11 +11,10 @@ width: 100%; } - .header { user-select: none; height: 60px; - background: #1e88e5; + background: #409EFF; color: white; display: flex; align-items: center; @@ -28,38 +27,6 @@ font-weight: bold; } - .header-user { - margin-left: auto; - display: flex; - align-items: center; - gap: 10px; - } - - .user-avatar { - width: 32px; - height: 32px; - border-radius: 50%; - object-fit: cover; - } - - .user-name { - font-size: 14px; - } - - .logout-btn { - padding: 5px 10px; - background: #fff; - color: #1e88e5; - border: none; - border-radius: 4px; - cursor: pointer; - transition: all 0.2s; - } - - .logout-btn:hover { - background: #f5f5f5; - } - .main-container { display: flex; flex: 1; @@ -113,21 +80,12 @@
-
- 用户头像 - {{ user.name }} - -
-
- 未登录 - - 登录 - + 首页
+ 应用权限管理 + +
+
@@ -153,109 +111,14 @@
diff --git a/new/ui/layout/header.html b/new/ui/layout/header.html deleted file mode 100644 index e69de29..0000000 diff --git a/new/ui/page/a/a b/new/ui/page/a/a deleted file mode 100644 index e69de29..0000000 diff --git a/new/ui/page/a/test.html b/new/ui/page/a/test.html deleted file mode 100644 index 797c477..0000000 --- a/new/ui/page/a/test.html +++ /dev/null @@ -1,124 +0,0 @@ - - - - CPU 负载图 - - - -
-
CPU 负载 (%)
- -
- - - - diff --git a/new/ui/page/app.html b/new/ui/page/app.html index 60a65ef..0f0b073 100644 --- a/new/ui/page/app.html +++ b/new/ui/page/app.html @@ -329,7 +329,7 @@
-

{{ app.name }}

+

{{ app.name }}{{app.cid}}

{{ app.status }} @@ -402,7 +402,9 @@ } else if (selectedFilter === 'users') { result.sort((a, b) => b.user_count - a.user_count); } - + result.forEach((app, id) => { + app.cid = id + }) return result; }; diff --git a/new/ui/page/app/main.html b/new/ui/page/app/main.html index 1e8daec..d31bdfd 100644 --- a/new/ui/page/app/main.html +++ b/new/ui/page/app/main.html @@ -314,13 +314,8 @@ history.back() }) } - sync() - // 初始化加载 - diff --git a/new/ui/page/app/user.html b/new/ui/page/app/user.html index 9fffa5a..9aa91b1 100644 --- a/new/ui/page/app/user.html +++ b/new/ui/page/app/user.html @@ -30,7 +30,7 @@
应用用户管理
- + 权限表 @@ -50,6 +50,7 @@ 2: ['申请中', 'primary'], 3: ['禁用', 'warning'], } + user_api = ($env.root || '') + '/api/user' keys = [ { name: 'id', @@ -59,7 +60,6 @@ { name: 'username', label: '用户名', - editable: true, style: 'text-align: left', sortable: true }, @@ -67,6 +67,7 @@ name: 'nickname', label: '昵称', style: 'text-align: left', + editable: true, sortable: true }, {name: 'created_at', label: '创建时间', field: (r) => new Date(r.created_at).toLocaleString()}, @@ -97,7 +98,7 @@ show_user = async (row) => { selected = row console.log(row) - user_role_url = ($env.root || '') + `/api/user/${$env.user.uid}/user_role` + user_role_url = ($env.root || '') + `/api/user/${Guser.uid}/user_role` // accessData = await access_api.next(0, 10) user_role_data = await user_role_api.next(0, 10) show = true diff --git a/new/ui/page/index.html b/new/ui/page/index.html index 4eea40c..0e4eeae 100644 --- a/new/ui/page/index.html +++ b/new/ui/page/index.html @@ -1,54 +1,697 @@ - + - - Index2 + 项目与用户管理 Dashboard + + - - - -