From 84c9206d2246c55469e7eb1fc02f462a648231d8 Mon Sep 17 00:00:00 2001 From: fancl Date: Fri, 13 Dec 2024 16:09:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 11 ++ config/config.yaml | 2 +- generator/main.go | 190 ++++++++++++++++++++++++++ web/src/assets/scss/common.scss | 5 + web/src/layouts/default/Headerbar.vue | 45 +----- web/src/layouts/default/Layout.vue | 2 - web/src/layouts/default/Statusbar.vue | 12 +- web/src/stores/system.js | 2 +- 8 files changed, 220 insertions(+), 49 deletions(-) create mode 100644 Makefile create mode 100644 generator/main.go diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dc0b080 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +GOPATH:=$(shell go env GOPATH) +DATETIME:=$(shell date "+%Y-%m-%d %H:%M:%S") +PKGNAME:="git.nobla.cn/golang/moto" +GIT_VERSION=$(shell git rev-parse --short HEAD) + +.PHONY: build + +build: + go mod tidy + go mod vendor + CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "-s -w -X '$(PKGNAME)/version.Version=$(GIT_VERSION)' -X '$(PKGNAME)/version.BuildDate=$(DATETIME)'" -o ./bin/$(APP_NAME) ./cmd/main.go \ No newline at end of file diff --git a/config/config.yaml b/config/config.yaml index b08e3bf..11b4277 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -10,4 +10,4 @@ adminUsers: system: settings: productName: "测试网址" - copyright: "xxx" \ No newline at end of file + copyright: "版权所有,防盗必究" \ No newline at end of file diff --git a/generator/main.go b/generator/main.go new file mode 100644 index 0000000..9d971d6 --- /dev/null +++ b/generator/main.go @@ -0,0 +1,190 @@ +package main + +import ( + "archive/tar" + "bytes" + "compress/gzip" + "errors" + "flag" + "fmt" + "io" + "net/http" + "os" + "path" + "runtime" + "strconv" + "strings" + "time" +) + +var ( + packageNameFlag = flag.String("package-name", "github.com/golang/example", "Application package name") + versionFlag = flag.String("version", "v0.0.1", "Application package version") +) + +var ( + oldPackageName = "git.nobla.cn/golang/moto" +) + +func writeFile(dstFile string, r io.Reader) (err error) { + var ( + fp *os.File + ) + if fp, err = os.Create(dstFile); err != nil { + return + } + defer fp.Close() + _, err = io.Copy(fp, r) + return +} + +func extractFile(file string, dirname string) (err error) { + var ( + prefix string + fp *os.File + gzipReader *gzip.Reader + ) + // 清理路径字符串 + dirname = path.Clean(dirname) + + // 打开压缩文件 + if fp, err = os.Open(file); err != nil { + return + } + defer fp.Close() + // 执行解压操作 + if gzipReader, err = gzip.NewReader(fp); err != nil { + return + } + defer gzipReader.Close() + tarReader := tar.NewReader(gzipReader) + for { + header, errRead := tarReader.Next() + if errRead != nil { + if errors.Is(errRead, io.EOF) { + break + } + err = errRead + break + } + if header.Typeflag == tar.TypeXGlobalHeader { + continue + } + fileInfo := header.FileInfo() + if prefix == "" && header.Typeflag == tar.TypeDir { + prefix = header.Name + continue + } + filename := path.Join(dirname, strings.TrimPrefix(header.Name, prefix)) + if header.Typeflag == tar.TypeDir { + if err = os.MkdirAll(filename, fileInfo.Mode().Perm()); err != nil { + return + } + if runtime.GOOS != "windows" { + if err = os.Chmod(filename, fileInfo.Mode().Perm()); err != nil { + return + } + } + } else { + if err = writeFile(filename, tarReader); err != nil { + return err + } + if runtime.GOOS != "windows" { + if err = os.Chmod(filename, fileInfo.Mode().Perm()); err != nil { + return + } + } + } + } + return nil +} + +func downloadPackage(version string, dirname string) (err error) { + var ( + uri string + res *http.Response + ) + uri = "https://git.nobla.cn/golang/moto/archive/" + version + ".tar.gz" + if res, err = http.Get(uri); err != nil { + return + } + defer func() { + res.Body.Close() + }() + if res.StatusCode != http.StatusOK { + err = errors.New(res.Status) + return + } + filename := path.Join(os.TempDir(), strconv.FormatInt(time.Now().UnixMilli(), 10)+".tar.gz") + if err = writeFile(filename, res.Body); err != nil { + return + } + err = extractFile(filename, dirname) + return +} + +func replaceFiles(dirname string, source, replace string) (err error) { + var ( + buf []byte + files []os.DirEntry + ) + if files, err = os.ReadDir(dirname); err != nil { + if errors.Is(err, io.EOF) { + return nil + } + return err + } + sb := []byte(source) + rb := []byte(replace) + for _, file := range files { + if file.Name() == "." || file.Name() == ".." { + continue + } + filename := path.Join(dirname, file.Name()) + if file.IsDir() { + err = replaceFiles(filename, source, replace) + } else { + if buf, err = os.ReadFile(filename); err == nil { + buf = bytes.ReplaceAll(buf, sb, rb) + os.WriteFile(filename, buf, 064) + } + } + } + return +} + +func main() { + var ( + pos int + err error + dirname string + appname string + packageName string + ) + flag.Parse() + packageName = *packageNameFlag + pos = strings.LastIndexByte(packageName, '/') + if pos == -1 { + fmt.Println("package name invalid") + os.Exit(1) + } + appname = packageName[pos:] + if dirname, err = os.Getwd(); err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + dirname = path.Join(dirname, appname) + if err = os.MkdirAll(dirname, 0755); err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + if err = downloadPackage(*versionFlag, dirname); err != nil { + fmt.Println("download file error:" + err.Error()) + os.Exit(1) + } + if err = replaceFiles(dirname, oldPackageName, packageName); err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + fmt.Println("Create project successful !!!") +} diff --git a/web/src/assets/scss/common.scss b/web/src/assets/scss/common.scss index bea3af8..d5c0195 100644 --- a/web/src/assets/scss/common.scss +++ b/web/src/assets/scss/common.scss @@ -60,6 +60,11 @@ } } + + .el-select { + --el-border-color: var(--form-control-border-color); + } + .el-input { --el-input-border-color: var(--form-control-border-color); diff --git a/web/src/layouts/default/Headerbar.vue b/web/src/layouts/default/Headerbar.vue index 77d9720..5ff9716 100644 --- a/web/src/layouts/default/Headerbar.vue +++ b/web/src/layouts/default/Headerbar.vue @@ -28,12 +28,9 @@
-
\ No newline at end of file diff --git a/web/src/stores/system.js b/web/src/stores/system.js index 7ba402e..6c40cb8 100644 --- a/web/src/stores/system.js +++ b/web/src/stores/system.js @@ -10,7 +10,7 @@ const useSystemStore = defineStore('system', { lang: 'zh-CN', logoUrl: '//s3.tebi.io/tenos/images/logo/jc.png', copyright: '2005-2023 JUSTCALL 版权 © 2023 集时股份呼叫中心开发团队', - productName: '在线系统', + productName: '管理系统', variables: {}, } },