diff --git a/mayfly_go_web/package.json b/mayfly_go_web/package.json index e27f4511..12e5faa1 100644 --- a/mayfly_go_web/package.json +++ b/mayfly_go_web/package.json @@ -33,7 +33,7 @@ "splitpanes": "^3.1.5", "sql-formatter": "^14.0.0", "uuid": "^9.0.1", - "vue": "^3.3.11", + "vue": "^3.3.12", "vue-router": "^4.2.5", "xterm": "^5.3.0", "xterm-addon-fit": "^0.8.0", diff --git a/mayfly_go_web/src/components/SearchForm/components/SearchFormItem.vue b/mayfly_go_web/src/components/SearchForm/components/SearchFormItem.vue index 55400de8..830911ef 100644 --- a/mayfly_go_web/src/components/SearchForm/components/SearchFormItem.vue +++ b/mayfly_go_web/src/components/SearchForm/components/SearchFormItem.vue @@ -67,7 +67,7 @@ const handleSearchProps = computed(() => { // 处理透传的 事件 const handleEvents = computed(() => { - let itemEvents = props.item?.props ?? {}; + let itemEvents = props.item?.events ?? {}; return itemEvents; }); diff --git a/mayfly_go_web/src/components/SearchForm/index.ts b/mayfly_go_web/src/components/SearchForm/index.ts index cc8276c2..fe76723a 100644 --- a/mayfly_go_web/src/components/SearchForm/index.ts +++ b/mayfly_go_web/src/components/SearchForm/index.ts @@ -49,6 +49,13 @@ export class OptionsApi { */ convertFn: (apiResp: any) => any; + // remote: boolean = false; + + /** + * 远程方法参数属性字段,存在该值,则说明使用remote-method进行远程搜索 + */ + remoteMethodParamProp: string; + withConvertFn(fn: (apiResp: any) => any) { this.convertFn = fn; return this; @@ -72,6 +79,15 @@ export class OptionsApi { return this; } + /** + * 是否使用select的remote方式远程搜索调用 + * @param remoteReqParamKey remote请求参数对应的prop,需要将输入的value赋值给params[paramProp]进行远程搜索 + */ + isRemote(paramProp: string) { + this.remoteMethodParamProp = paramProp; + return this; + } + /** * 调用api获取组件可选项 * @returns 组件可选项信息 @@ -228,7 +244,7 @@ export class SearchItem { if (!this.events) { this.events = {}; } - this.props[event] = eventFn; + this.events[event] = eventFn; return this; } @@ -252,6 +268,19 @@ export class SearchItem { // 使用api获取组件可选项需要将options转为响应式,否则组件无法响应式获取组件可选项 this.options = ref(null); + // 存在远程搜索请求参数prop,则为使用远程搜索可选项 + if (optionsApi.remoteMethodParamProp) { + return this.withOneProps('remote', true).withOneProps('remote-method', async (value: any) => { + if (!value) { + this.options.value = []; + return; + } + // 将输入的内容赋值为真实api请求参数中指定的属性字段 + optionsApi.params[optionsApi.remoteMethodParamProp] = value; + this.options.value = await this.optionsApi.getOptions(); + }); + } + // 立即执行,则直接调用api获取并赋值options if (this.optionsApi.immediate) { this.optionsApi.getOptions().then((res) => { @@ -277,4 +306,13 @@ export class SearchItem { this.options = options; return this; } + + /** + * 赋值placeholder + * @param val placeholder + * @returns + */ + withPlaceholder(val: string): SearchItem { + return this.withOneProps('placeholder', val); + } } diff --git a/mayfly_go_web/src/views/ops/db/component/table/DbTableData.vue b/mayfly_go_web/src/views/ops/db/component/table/DbTableData.vue index 9107335d..825b7d06 100644 --- a/mayfly_go_web/src/views/ops/db/component/table/DbTableData.vue +++ b/mayfly_go_web/src/views/ops/db/component/table/DbTableData.vue @@ -882,7 +882,7 @@ defineExpose({ } .update_field_active { - background-color: var(--el-color-success); + background-color: var(--el-color-success-light-3); } .column-type { diff --git a/mayfly_go_web/src/views/system/syslog/SyslogList.vue b/mayfly_go_web/src/views/system/syslog/SyslogList.vue index 7e548db1..31770c17 100755 --- a/mayfly_go_web/src/views/system/syslog/SyslogList.vue +++ b/mayfly_go_web/src/views/system/syslog/SyslogList.vue @@ -1,12 +1,6 @@ @@ -16,10 +10,24 @@ import { logApi, accountApi } from '../api'; import PageTable from '@/components/pagetable/PageTable.vue'; import { TableColumn } from '@/components/pagetable'; import { LogTypeEnum } from '../enums'; -import { SearchItem } from '@/components/SearchForm'; +import { OptionsApi, SearchItem } from '@/components/SearchForm'; const searchItems = [ - SearchItem.slot('creatorId', '操作人', 'selectAccount'), + SearchItem.select('creatorId', '操作人') + .withPlaceholder('请输入并选择账号') + .withOptionsApi( + OptionsApi.new(accountApi.list, { username: null }) + .withConvertFn((res: any) => { + const accounts = res.list; + return accounts.map((x: any) => { + return { + label: x.username, + value: x.id, + }; + }); + }) + .isRemote('username') + ), SearchItem.select('type', '操作结果').withEnum(LogTypeEnum), SearchItem.input('description', '描述'), ]; @@ -41,18 +49,8 @@ const state = reactive({ pageNum: 1, pageSize: 0, }, - accounts: [] as any, }); -const { query, accounts } = toRefs(state); - -const getAccount = (username: any) => { - if (!username) { - return; - } - accountApi.list.request({ username }).then((res) => { - state.accounts = res.list; - }); -}; +const { query } = toRefs(state); diff --git a/mayfly_go_web/yarn.lock b/mayfly_go_web/yarn.lock index fe98ccba..bbe04230 100644 --- a/mayfly_go_web/yarn.lock +++ b/mayfly_go_web/yarn.lock @@ -450,6 +450,16 @@ estree-walker "^2.0.2" source-map-js "^1.0.2" +"@vue/compiler-core@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/compiler-core/-/compiler-core-3.3.12.tgz#3346c0f55ce0d59e17c21d9eef9154b70c19931b" + integrity sha512-qAtjyG3GBLG0chzp5xGCyRLLe6wFCHmjI82aGzwuGKyznNP+GJJMxjc0wOYWDB2YKfho7niJFdoFpo0CZZQg9w== + dependencies: + "@babel/parser" "^7.23.5" + "@vue/shared" "3.3.12" + estree-walker "^2.0.2" + source-map-js "^1.0.2" + "@vue/compiler-dom@3.3.11": version "3.3.11" resolved "https://registry.npmmirror.com/@vue/compiler-dom/-/compiler-dom-3.3.11.tgz#36a76ea3a296d41bad133a6912cb0a847d969e4f" @@ -458,7 +468,31 @@ "@vue/compiler-core" "3.3.11" "@vue/shared" "3.3.11" -"@vue/compiler-sfc@3.3.11", "@vue/compiler-sfc@^3.3.11": +"@vue/compiler-dom@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/compiler-dom/-/compiler-dom-3.3.12.tgz#267c54b388d58f30fc120ea496ebf27d4ea8368b" + integrity sha512-RdJU9oEYaoPKUdGXCy0l+i4clesdDeLmbvRlszoc9iagsnBnMmQtYfCPVQ5BHB6o7K4SCucDdJM2Dh3oXB0D6g== + dependencies: + "@vue/compiler-core" "3.3.12" + "@vue/shared" "3.3.12" + +"@vue/compiler-sfc@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/compiler-sfc/-/compiler-sfc-3.3.12.tgz#6ec2c19858f264671457699c1f3a0a6fedf429fe" + integrity sha512-yy5b9e7b79dsGbMmglCe/YnhCQgBkHO7Uf6JfjWPSf2/5XH+MKn18LhzhHyxbHdJgnA4lZCqtXzLaJz8Pd8lMw== + dependencies: + "@babel/parser" "^7.23.5" + "@vue/compiler-core" "3.3.12" + "@vue/compiler-dom" "3.3.12" + "@vue/compiler-ssr" "3.3.12" + "@vue/reactivity-transform" "3.3.12" + "@vue/shared" "3.3.12" + estree-walker "^2.0.2" + magic-string "^0.30.5" + postcss "^8.4.32" + source-map-js "^1.0.2" + +"@vue/compiler-sfc@^3.3.11": version "3.3.11" resolved "https://registry.npmmirror.com/@vue/compiler-sfc/-/compiler-sfc-3.3.11.tgz#acfae240c875d067e0e2c9a4e2d910074408c73b" integrity sha512-U4iqPlHO0KQeK1mrsxCN0vZzw43/lL8POxgpzcJweopmqtoYy9nljJzWDIQS3EfjiYhfdtdk9Gtgz7MRXnz3GA== @@ -482,6 +516,14 @@ "@vue/compiler-dom" "3.3.11" "@vue/shared" "3.3.11" +"@vue/compiler-ssr@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/compiler-ssr/-/compiler-ssr-3.3.12.tgz#e62499c6003ccd09acb7190167d08845e3a0eaa5" + integrity sha512-adCiMJPznfWcQyk/9HSuXGja859IaMV+b8UNSVzDatqv7h0PvT9BEeS22+gjkWofDiSg5d78/ZLls3sLA+cn3A== + dependencies: + "@vue/compiler-dom" "3.3.12" + "@vue/shared" "3.3.12" + "@vue/devtools-api@^6.5.0": version "6.5.0" resolved "https://registry.npmmirror.com/@vue/devtools-api/-/devtools-api-6.5.0.tgz#98b99425edee70b4c992692628fa1ea2c1e57d07" @@ -498,43 +540,59 @@ estree-walker "^2.0.2" magic-string "^0.30.5" -"@vue/reactivity@3.3.11": - version "3.3.11" - resolved "https://registry.npmmirror.com/@vue/reactivity/-/reactivity-3.3.11.tgz#91f8e6c9ac60a595a5278c836b197628fd947a0d" - integrity sha512-D5tcw091f0nuu+hXq5XANofD0OXnBmaRqMYl5B3fCR+mX+cXJIGNw/VNawBqkjLNWETrFW0i+xH9NvDbTPVh7g== +"@vue/reactivity-transform@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/reactivity-transform/-/reactivity-transform-3.3.12.tgz#4cb871b597eb8b321577b4d7f1e93eaebca16128" + integrity sha512-g5TijmML7FyKkLt6QnpqNmA4KD7K/T5SbXa88Bhq+hydNQEkzA8veVXWAQuNqg9rjaFYD0rPf0a9NofKA0ENgg== dependencies: - "@vue/shared" "3.3.11" + "@babel/parser" "^7.23.5" + "@vue/compiler-core" "3.3.12" + "@vue/shared" "3.3.12" + estree-walker "^2.0.2" + magic-string "^0.30.5" -"@vue/runtime-core@3.3.11": - version "3.3.11" - resolved "https://registry.npmmirror.com/@vue/runtime-core/-/runtime-core-3.3.11.tgz#63defba57bc54c1dac68a95b56c2633b1419193d" - integrity sha512-g9ztHGwEbS5RyWaOpXuyIVFTschclnwhqEbdy5AwGhYOgc7m/q3NFwr50MirZwTTzX55JY8pSkeib9BX04NIpw== +"@vue/reactivity@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/reactivity/-/reactivity-3.3.12.tgz#b4a62a7678ab20c1ef32f991342ddbb8532417da" + integrity sha512-vOJORzO8DlIx88cgTnMLIf2GlLYpoXAKsuoQsK6SGdaqODjxO129pVPTd2s/N/Mb6KKZEFIHIEwWGmtN4YPs+g== dependencies: - "@vue/reactivity" "3.3.11" - "@vue/shared" "3.3.11" + "@vue/shared" "3.3.12" -"@vue/runtime-dom@3.3.11": - version "3.3.11" - resolved "https://registry.npmmirror.com/@vue/runtime-dom/-/runtime-dom-3.3.11.tgz#1146d8d280b0fec4d2e18c4a4c8f8121d0cecc09" - integrity sha512-OlhtV1PVpbgk+I2zl+Y5rQtDNcCDs12rsRg71XwaA2/Rbllw6mBLMi57VOn8G0AjOJ4Mdb4k56V37+g8ukShpQ== +"@vue/runtime-core@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/runtime-core/-/runtime-core-3.3.12.tgz#67ee6cfc2e85d656946975239ea635ec42dde5f6" + integrity sha512-5iL4w7MZrSGKEZU2wFAYhDZdZmgn+s//73EfgDXW1M+ZUOl36md7tlWp1QFK/ladiq4FvQ82shVjo0KiPDPr0A== dependencies: - "@vue/runtime-core" "3.3.11" - "@vue/shared" "3.3.11" - csstype "^3.1.2" + "@vue/reactivity" "3.3.12" + "@vue/shared" "3.3.12" -"@vue/server-renderer@3.3.11": - version "3.3.11" - resolved "https://registry.npmmirror.com/@vue/server-renderer/-/server-renderer-3.3.11.tgz#409aed8031a125791e2143552975ecd1958ad601" - integrity sha512-AIWk0VwwxCAm4wqtJyxBylRTXSy1wCLOKbWxHaHiu14wjsNYtiRCSgVuqEPVuDpErOlRdNnuRgipQfXRLjLN5A== +"@vue/runtime-dom@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/runtime-dom/-/runtime-dom-3.3.12.tgz#28a239496e589037774cba7c1b27057242eedb11" + integrity sha512-8mMzqiIdl+IYa/OXwKwk6/4ebLq7cYV1pUcwCSwBK2KerUa6cwGosen5xrCL9f8o2DJ9TfPFwbPEvH7OXzUpoA== dependencies: - "@vue/compiler-ssr" "3.3.11" - "@vue/shared" "3.3.11" + "@vue/runtime-core" "3.3.12" + "@vue/shared" "3.3.12" + csstype "^3.1.3" + +"@vue/server-renderer@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/server-renderer/-/server-renderer-3.3.12.tgz#f0246aba5d5d6fdfa840ac9e4f32d76f03b20665" + integrity sha512-OZ0IEK5TU5GXb5J8/wSplyxvGGdIcwEmS8EIO302Vz8K6fGSgSJTU54X0Sb6PaefzZdiN3vHsLXO8XIeF8crQQ== + dependencies: + "@vue/compiler-ssr" "3.3.12" + "@vue/shared" "3.3.12" "@vue/shared@3.3.11": version "3.3.11" resolved "https://registry.npmmirror.com/@vue/shared/-/shared-3.3.11.tgz#f6a038e15237edefcc90dbfe7edb806dd355c7bd" integrity sha512-u2G8ZQ9IhMWTMXaWqZycnK4UthG1fA238CD+DP4Dm4WJi5hdUKKLg0RMRaRpDPNMdkTwIDkp7WtD0Rd9BH9fLw== +"@vue/shared@3.3.12": + version "3.3.12" + resolved "https://registry.npmmirror.com/@vue/shared/-/shared-3.3.12.tgz#7c030c4e2f1db8beb638b159cbb86d0ff78c3198" + integrity sha512-6p0Yin0pclvnER7BLNOQuod9Z+cxSYh8pSh7CzHnWNjAIP6zrTlCdHRvSCb1aYEx6i3Q3kvfuWU7nG16CgG1ag== + "@vueuse/core@^10.7.0": version "10.7.0" resolved "https://registry.npmmirror.com/@vueuse/core/-/core-10.7.0.tgz#34f2f02f179dc0dcffc2be70d6b1233e011404b9" @@ -786,10 +844,10 @@ csstype@^3.1.0: resolved "https://registry.npmmirror.com/csstype/-/csstype-3.1.1.tgz" integrity sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw== -csstype@^3.1.2: - version "3.1.2" - resolved "https://registry.npmmirror.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b" - integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ== +csstype@^3.1.3: + version "3.1.3" + resolved "https://registry.npmmirror.com/csstype/-/csstype-3.1.3.tgz#d80ff294d114fb0e6ac500fbf85b60137d7eff81" + integrity sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw== dayjs@^1.11.3: version "1.11.3" @@ -1945,16 +2003,16 @@ vue-router@^4.2.5: dependencies: "@vue/devtools-api" "^6.5.0" -vue@^3.3.11: - version "3.3.11" - resolved "https://registry.npmmirror.com/vue/-/vue-3.3.11.tgz#898d97025f73cdb5fc4e3ae3fd07a54615232140" - integrity sha512-d4oBctG92CRO1cQfVBZp6WJAs0n8AK4Xf5fNjQCBeKCvMI1efGQ5E3Alt1slFJS9fZuPcFoiAiqFvQlv1X7t/w== +vue@^3.3.12: + version "3.3.12" + resolved "https://registry.npmmirror.com/vue/-/vue-3.3.12.tgz#4a3a39e79d22e9826ae7c058863316333c838b63" + integrity sha512-jYNv2QmET2OTHsFzfWHMnqgCfqL4zfo97QwofdET+GBRCHhSCHuMTTvNIgeSn0/xF3JRT5OGah6MDwUFN7MPlg== dependencies: - "@vue/compiler-dom" "3.3.11" - "@vue/compiler-sfc" "3.3.11" - "@vue/runtime-dom" "3.3.11" - "@vue/server-renderer" "3.3.11" - "@vue/shared" "3.3.11" + "@vue/compiler-dom" "3.3.12" + "@vue/compiler-sfc" "3.3.12" + "@vue/runtime-dom" "3.3.12" + "@vue/server-renderer" "3.3.12" + "@vue/shared" "3.3.12" which@^2.0.1: version "2.0.2" diff --git a/server/.gitignore b/server/.gitignore index b83958ee..900776b3 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1,2 +1,4 @@ static/static config.yml +mayfly_rsa +mayfly_rsa.pub \ No newline at end of file diff --git a/server/pkg/utils/cryptox/cryptox.go b/server/pkg/utils/cryptox/cryptox.go index 401059c6..a18fa6ec 100644 --- a/server/pkg/utils/cryptox/cryptox.go +++ b/server/pkg/utils/cryptox/cryptox.go @@ -13,6 +13,8 @@ import ( "encoding/pem" "errors" "mayfly-go/pkg/cache" + "mayfly-go/pkg/logx" + "os" "golang.org/x/crypto/bcrypt" ) @@ -128,37 +130,68 @@ func DefaultRsaDecrypt(data string, useBase64 bool) (string, error) { return string(val), nil } -const publicKeyK = "mayfly:public-key" -const privateKeyK = "mayfly:private-key" +const ( + // 公钥文件路径 + publicKeyFile = "./mayfly_rsa.pub" + // 私钥文件路径 + privateKeyFile = "./mayfly_rsa" + + publicKeyK = "mayfly:public-key" + privateKeyK = "mayfly:private-key" +) // 获取系统的RSA公钥 func GetRsaPublicKey() (string, error) { - publicKey := cache.GetStr(publicKeyK) - if publicKey != "" { - return publicKey, nil - } - privateKey, publicKey, err := GenerateRSAKey(1024) + content, err := os.ReadFile(publicKeyFile) if err != nil { - return "", err + publicKey := cache.GetStr(publicKeyK) + if publicKey != "" { + return publicKey, nil + } + _, pubKey, err := GenerateAndSaveRSAKey() + return pubKey, err } - cache.SetStr(publicKeyK, publicKey, -1) - cache.SetStr(privateKeyK, privateKey, -1) - return publicKey, nil + + return string(content), nil } // 获取系统私钥 func GetRsaPrivateKey() (string, error) { - privateKey := cache.GetStr(privateKeyK) - if privateKey != "" { - return privateKey, nil + content, err := os.ReadFile(privateKeyFile) + if err != nil { + privateKey := cache.GetStr(privateKeyK) + if privateKey != "" { + return privateKey, nil + } + privateKey, _, err := GenerateAndSaveRSAKey() + return privateKey, err } + + return string(content), nil +} + +// 生成并保存rsa key,优先保存于磁盘,若磁盘保存失败,则保存至缓存 +// +// 依次返回 privateKey, publicKey, error +func GenerateAndSaveRSAKey() (string, string, error) { privateKey, publicKey, err := GenerateRSAKey(1024) if err != nil { - return "", err + return "", "", err } - cache.SetStr(publicKeyK, publicKey, -1) - cache.SetStr(privateKeyK, privateKey, -1) - return privateKey, nil + + err = os.WriteFile(privateKeyFile, []byte(privateKey), 0644) + if err != nil { + logx.ErrorTrace("RSA私钥写入磁盘文件失败, 使用缓存存储该私钥", err) + cache.SetStr(privateKeyK, privateKey, -1) + } + + err = os.WriteFile(publicKeyFile, []byte(publicKey), 0644) + if err != nil { + logx.ErrorTrace("RSA公钥写入磁盘文件失败, 使用缓存存储该公钥", err) + cache.SetStr(publicKeyK, publicKey, -1) + } + + return privateKey, publicKey, nil } // AesEncrypt 加密