From 346ade21f1376eb28a2d3fb121a73de868ebe6f9 Mon Sep 17 00:00:00 2001 From: kenneth <1185230223@qq.com> Date: Mon, 16 Jun 2025 10:38:00 +0800 Subject: [PATCH] change use strings builder --- go.mod | 20 +- go.sum | 39 +-- internal/erpserver/templ/component/btn.go | 276 ++++++++++---------- internal/erpserver/templ/component/btnv1.go | 126 +++++++++ 4 files changed, 294 insertions(+), 167 deletions(-) create mode 100644 internal/erpserver/templ/component/btnv1.go diff --git a/go.mod b/go.mod index 191d537..dbf0075 100644 --- a/go.mod +++ b/go.mod @@ -15,22 +15,22 @@ require ( github.com/google/uuid v1.6.0 github.com/google/wire v0.6.0 github.com/h2non/filetype v1.1.3 - github.com/jackc/pgx/v5 v5.7.4 + github.com/jackc/pgx/v5 v5.7.5 github.com/json-iterator/go v1.1.12 - github.com/justinas/nosurf v1.1.1 + github.com/justinas/nosurf v1.2.0 github.com/matoous/go-nanoid/v2 v2.1.0 github.com/mojocn/base64Captcha v1.3.8 github.com/patrickmn/go-cache v2.1.0+incompatible - github.com/redis/go-redis/v9 v9.8.0 + github.com/redis/go-redis/v9 v9.10.0 github.com/spf13/cobra v1.9.1 github.com/spf13/viper v1.20.1 github.com/tdewolff/minify v2.3.6+incompatible github.com/zhang2092/browser v0.0.2 go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.38.0 + golang.org/x/crypto v0.39.0 golang.org/x/sync v0.15.0 gorm.io/datatypes v1.2.5 - gorm.io/driver/postgres v1.5.11 + gorm.io/driver/postgres v1.6.0 gorm.io/gorm v1.30.0 ) @@ -40,7 +40,7 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/gabriel-vasile/mimetype v1.4.9 // indirect - github.com/go-sql-driver/mysql v1.9.2 // indirect + github.com/go-sql-driver/mysql v1.9.3 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect @@ -50,21 +50,21 @@ require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/leodido/go-urn v1.4.0 // indirect - github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/sagikazarmark/locafero v0.9.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.14.0 // indirect - github.com/spf13/cast v1.8.0 // indirect + github.com/spf13/cast v1.9.2 // indirect github.com/spf13/pflag v1.0.6 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/tdewolff/parse v2.3.4+incompatible // indirect github.com/tdewolff/test v1.0.11 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/image v0.27.0 // indirect - golang.org/x/net v0.40.0 // indirect + golang.org/x/image v0.28.0 // indirect + golang.org/x/net v0.41.0 // indirect golang.org/x/sys v0.33.0 // indirect golang.org/x/text v0.26.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 79769fe..2156df3 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k= github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= -github.com/go-sql-driver/mysql v1.9.2 h1:4cNKDYQ1I84SXslGddlsrMhc8k4LeDVj6Ad6WRjiHuU= -github.com/go-sql-driver/mysql v1.9.2/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= +github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo= +github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= @@ -69,8 +69,8 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.7.4 h1:9wKznZrhWa2QiHL+NjTSPP6yjl3451BX3imWDnokYlg= -github.com/jackc/pgx/v5 v5.7.4/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= +github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs= +github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= @@ -81,8 +81,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/justinas/nosurf v1.1.1 h1:92Aw44hjSK4MxJeMSyDa7jwuI9GR2J/JCQiaKvXXSlk= -github.com/justinas/nosurf v1.1.1/go.mod h1:ALpWdSbuNGy2lZWtyXdjkYv4edL23oSEgfBT1gPJ5BQ= +github.com/justinas/nosurf v1.2.0 h1:yMs1bSRrNiwXk4AS6n8vL2Ssgpb9CB25T/4xrixaK0s= +github.com/justinas/nosurf v1.2.0/go.mod h1:ALpWdSbuNGy2lZWtyXdjkYv4edL23oSEgfBT1gPJ5BQ= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -95,8 +95,9 @@ github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOj github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/microsoft/go-mssqldb v1.7.2 h1:CHkFJiObW7ItKTJfHo1QX7QBBD1iV+mn1eOyRP3b/PA= github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mojocn/base64Captcha v1.3.8 h1:rrN9BhCwXKS8ht1e21kvR3iTaMgf4qPC9sRoV52bqEg= @@ -109,8 +110,8 @@ github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0 github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/redis/go-redis/v9 v9.8.0 h1:q3nRvjrlge/6UD7eTu/DSg2uYiU2mCL0G/uzBWqhicI= -github.com/redis/go-redis/v9 v9.8.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw= +github.com/redis/go-redis/v9 v9.10.0 h1:FxwK3eV8p/CQa0Ch276C7u2d0eNC9kCmAYQ7mCXCzVs= +github.com/redis/go-redis/v9 v9.10.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -124,8 +125,8 @@ github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9yS github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA= github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo= -github.com/spf13/cast v1.8.0 h1:gEN9K4b8Xws4EX0+a0reLmhq8moKn7ntRlQYgjPeCDk= -github.com/spf13/cast v1.8.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE= +github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= @@ -160,11 +161,11 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= -golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= +golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM= +golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U= golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY= -golang.org/x/image v0.27.0 h1:C8gA4oWU/tKkdCfYT6T2u4faJu3MeNS5O8UPWlPF61w= -golang.org/x/image v0.27.0/go.mod h1:xbdrClrAUway1MUTEZDq9mz/UpRwYAkFFNUslZtcB+g= +golang.org/x/image v0.28.0 h1:gdem5JW1OLS4FbkWgLO+7ZeFzYtL3xClb97GaUzYMFE= +golang.org/x/image v0.28.0/go.mod h1:GUJYXtnGKEUgggyzh+Vxt+AviiCcyiwpsl8iQ8MvwGY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= @@ -180,8 +181,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= -golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= +golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -246,8 +247,8 @@ gorm.io/datatypes v1.2.5 h1:9UogU3jkydFVW1bIVVeoYsTpLRgwDVW3rHfJG6/Ek9I= gorm.io/datatypes v1.2.5/go.mod h1:I5FUdlKpLb5PMqeMQhm30CQ6jXP8Rj89xkTeCSAaAD4= gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg= gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo= -gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= -gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= +gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4= +gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo= gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU= gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI= gorm.io/driver/sqlserver v1.5.4 h1:xA+Y1KDNspv79q43bPyjDMUgHoYHLhXYmdFcYPobg8g= diff --git a/internal/erpserver/templ/component/btn.go b/internal/erpserver/templ/component/btn.go index 82ebd33..4c04d8a 100644 --- a/internal/erpserver/templ/component/btn.go +++ b/internal/erpserver/templ/component/btn.go @@ -1,140 +1,140 @@ package component -import ( - "path/filepath" - "strings" - - "management/internal/erpserver/model/dto" - - "github.com/a-h/templ" -) - -func TemplBtn(buttons []dto.OwnerMenuDto, searchBtn bool, actionNames ...string) templ.Component { - var res string - if len(actionNames) == 0 { - return templ.Raw(res) - } - - if len(buttons) == 0 { - return templ.Raw(res) - } - - res = `` - return templ.Raw(res) -} - -func TemplLink(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component { - var res string - if len(actionNames) == 0 { - return templ.Raw(res) - } - - if len(buttons) == 0 { - return templ.Raw(res) - } - - res = `` - return templ.Raw(res) -} - -func GenBtn(buttons []dto.OwnerMenuDto, actionNames ...string) string { - var res string - if len(buttons) == 0 { - return res - } - - if len(actionNames) == 0 { - return res - } - - for _, action := range actionNames { - for _, btn := range buttons { - btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui") - base := filepath.Base(btn.Url) - if base == action { - res += `` - } - } - } - - return res -} - -func GenLink(buttons []dto.OwnerMenuDto, actionNames ...string) string { - if len(buttons) == 0 { - return "" - } - - if len(actionNames) == 0 { - return "" - } - - var res string - for _, action := range actionNames { - for _, btn := range buttons { - btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui") - base := filepath.Base(btn.Url) - if base == action { - res += `` - } - } - } - - return res -} - -func SubmitBtn(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component { - var res string - if len(buttons) == 0 { - return templ.Raw(res) - } - - if len(actionNames) == 0 { - return templ.Raw(res) - } - - for _, action := range actionNames { - for _, btn := range buttons { - btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui") - base := filepath.Base(btn.Url) - if base == action { - res += `` - } - } - } - - return templ.Raw(res) -} - -func firstLower(s string) string { - if len(s) == 0 { - return s - } - - return strings.ToLower(s[:1]) + s[1:] -} +//import ( +// "path/filepath" +// "strings" +// +// "management/internal/erpserver/model/dto" +// +// "github.com/a-h/templ" +//) +// +//func TemplBtn(buttons []dto.OwnerMenuDto, searchBtn bool, actionNames ...string) templ.Component { +// var res string +// if len(actionNames) == 0 { +// return templ.Raw(res) +// } +// +// if len(buttons) == 0 { +// return templ.Raw(res) +// } +// +// res = `` +// return templ.Raw(res) +//} +// +//func TemplLink(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component { +// var res string +// if len(actionNames) == 0 { +// return templ.Raw(res) +// } +// +// if len(buttons) == 0 { +// return templ.Raw(res) +// } +// +// res = `` +// return templ.Raw(res) +//} +// +//func GenBtn(buttons []dto.OwnerMenuDto, actionNames ...string) string { +// var res string +// if len(buttons) == 0 { +// return res +// } +// +// if len(actionNames) == 0 { +// return res +// } +// +// for _, action := range actionNames { +// for _, btn := range buttons { +// btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui") +// base := filepath.Base(btn.Url) +// if base == action { +// res += `` +// } +// } +// } +// +// return res +//} +// +//func GenLink(buttons []dto.OwnerMenuDto, actionNames ...string) string { +// if len(buttons) == 0 { +// return "" +// } +// +// if len(actionNames) == 0 { +// return "" +// } +// +// var res string +// for _, action := range actionNames { +// for _, btn := range buttons { +// btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui") +// base := filepath.Base(btn.Url) +// if base == action { +// res += `` +// } +// } +// } +// +// return res +//} +// +//func SubmitBtn(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component { +// var res string +// if len(buttons) == 0 { +// return templ.Raw(res) +// } +// +// if len(actionNames) == 0 { +// return templ.Raw(res) +// } +// +// for _, action := range actionNames { +// for _, btn := range buttons { +// btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui") +// base := filepath.Base(btn.Url) +// if base == action { +// res += `` +// } +// } +// } +// +// return templ.Raw(res) +//} +// +//func firstLower(s string) string { +// if len(s) == 0 { +// return s +// } +// +// return strings.ToLower(s[:1]) + s[1:] +//} diff --git a/internal/erpserver/templ/component/btnv1.go b/internal/erpserver/templ/component/btnv1.go new file mode 100644 index 0000000..208fb08 --- /dev/null +++ b/internal/erpserver/templ/component/btnv1.go @@ -0,0 +1,126 @@ +package component + +import ( + "path/filepath" + "strings" + + "management/internal/erpserver/model/dto" + + "github.com/a-h/templ" +) + +func TemplBtn(buttons []dto.OwnerMenuDto, searchBtn bool, actionNames ...string) templ.Component { + var b strings.Builder + b.WriteString(``) + return templ.Raw(b.String()) +} + +func TemplLink(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component { + var b strings.Builder + b.WriteString(``) + return templ.Raw(b.String()) +} + +func GenBtn(buttons []dto.OwnerMenuDto, actionNames ...string) string { + if len(buttons) == 0 { + return "" + } + + if len(actionNames) == 0 { + return "" + } + + var b strings.Builder + for _, action := range actionNames { + for _, btn := range buttons { + btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui") + base := filepath.Base(btn.Url) + if base == action { + b.WriteString(``) + } + } + } + + return b.String() +} + +func GenLink(buttons []dto.OwnerMenuDto, actionNames ...string) string { + if len(buttons) == 0 { + return "" + } + + if len(actionNames) == 0 { + return "" + } + + var b strings.Builder + for _, action := range actionNames { + for _, btn := range buttons { + btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui") + base := filepath.Base(btn.Url) + if base == action { + b.WriteString(``) + } + } + } + + return b.String() +} + +func SubmitBtn(buttons []dto.OwnerMenuDto, actionNames ...string) templ.Component { + if len(buttons) == 0 { + return templ.Raw("") + } + + if len(actionNames) == 0 { + return templ.Raw("") + } + + var b strings.Builder + for _, action := range actionNames { + for _, btn := range buttons { + btn.Style = strings.ReplaceAll(btn.Style, "pear", "layui") + base := filepath.Base(btn.Url) + if base == action { + b.WriteString(``) + } + } + } + + return templ.Raw(b.String()) +} + +func firstLower(s string) string { + if len(s) == 0 { + return s + } + + return strings.ToLower(s[:1]) + s[1:] +}