feat : add site custom setting

This commit is contained in:
engigu
2024-01-17 23:15:47 +08:00
parent 98985c2470
commit 69d4a1cc74
22 changed files with 174 additions and 61 deletions
+9
View File
@@ -18,6 +18,15 @@ Message Nest 是一个灵活而强大的消息推送整合平台,旨在简化
关于日志,考虑到目前多数服务以收集控制台输出为主,暂时不支持写出日志文件。
2024.01.07
- [x] 支持站点信息自定义
----
2024.01.03
- [x] 支持企业微信
----
- [x] 单应用打包
- [x] 支持邮件发送
- [x] 用户密码设置
+2 -4
View File
@@ -11,7 +11,6 @@ import (
"message-nest/pkg/setting"
"message-nest/routers"
"message-nest/service/cron_service"
"message-nest/service/env_service"
"net/http"
"os"
)
@@ -26,13 +25,12 @@ func init() {
logging.Setup()
migrate.Setup()
models.Setup()
env_service.Setup()
cron_service.Setup()
}
func main() {
gin.SetMode(setting.ServerSetting.RunMode)
cron_service.StartLogsCronRun()
gin.SetMode(setting.ServerSetting.RunMode)
routersInit := routers.InitRouter(f)
readTimeout := setting.ServerSetting.ReadTimeout
writeTimeout := setting.ServerSetting.WriteTimeout
+1
View File
@@ -13,6 +13,7 @@ import (
var ExcludedRoutes = []string{
"/api/v1/message/send",
"/api/v1/settings/getsetting",
}
// JWT is jwt middleware
+9
View File
@@ -7,8 +7,10 @@ import (
"github.com/sirupsen/logrus"
"message-nest/models"
"message-nest/pkg/setting"
"message-nest/service/settings_service"
)
// 初始化admin账户
func InitAuthTableData() {
initSection := "init"
initAuthKey := "account"
@@ -74,5 +76,12 @@ func Setup() {
entry.Infof("Init Account data...")
InitAuthTableData()
entry.Infof("Init Custom Site data...")
ss := settings_service.InitSettingService{}
ss.InitSiteConfig()
entry.Infof("Init Cron data...")
ss.InitLogConfig()
entry.Infof("All table data init done.")
}
+1 -1
View File
@@ -10,7 +10,7 @@ type Settings struct {
Section string `json:"section" gorm:"type:varchar(100) comment '实例类型';default:'';index:section"`
Key string `json:"key" gorm:"type:varchar(100) comment '实例类型';default:'';"`
Value string `json:"value" gorm:"type:varchar(4096) comment '实例类型';default:'';"`
Value string `json:"value" gorm:"type:text comment '实例类型';default:'';"`
}
// AddOneSetting 添加一条设置
+1
View File
@@ -10,6 +10,7 @@ const SiteSettingSectionName = "site_config"
// 站点信息默认值
var SiteSiteDefaultValueMap = map[string]string{
"title": "Message Nest",
"pagesize": "10",
"slogan": "A Message Way Hosted Site",
"logo": "<svg t=\"1702547210136\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"1861\" width=\"200\" height=\"200\"><path d=\"M970.091313 224.033616a14.201535 14.201535 0 0 0-14.100687-3.631838c-88.419556-13.429657-142.919111-12.953859-248.242424 23.762747-69.454869 24.217859-109.056 79.873293-135.267556 116.712728-6.692202 9.403475-18.949172 26.625293-23.77309 29.509818-5.70699-1.303273-21.929374-16.036202-31.762101-24.965172-28.626747-25.994343-64.252121-58.353778-106.767516-58.757172-0.312889-0.005172-0.627071-0.005172-0.939959-0.005171-29.62101 0-54.798222 13.434828-72.857859 38.89907-13.222788 18.651798-17.914828 37.388929-18.106182 38.176323a14.31402 14.31402 0 0 0 2.893576 12.515556 14.336 14.336 0 0 0 11.782465 5.095434l0.409858-0.024565c19.192242-1.152 59.141172-3.545212 65.807516 81.857939 4.288646 54.899071 29.742545 108.631919 69.833697 147.419798 45.499475 44.025535 106.237414 67.298263 175.650909 67.298263 98.97503 0 166.222869-24.480323 205.207272-45.015919 43.172202-22.742626 62.621737-45.918384 63.429819-46.898425a14.170505 14.170505 0 0 0 1.529535-15.874586 14.191192 14.191192 0 0 0-14.166626-7.337373c-37.924202 4.443798-92.767677 6.09099-138.666667-11.298909-7.580444-2.872889-13.878303-5.893172-18.959515-8.691071 20.273131-9.964606 51.000889-28.383677 83.621495-59.93503 34.186343-33.065374 37.722505-69.908687 40.838464-102.423273 2.297535-23.919192 4.666182-48.651636 18.500526-73.091879 28.807758-50.883232 66.645333-74.489535 74.560646-79.035475a14.201535 14.201535 0 0 0 12.135434-7.776969 14.193778 14.193778 0 0 0-2.59103-16.484849z\" fill=\"\" p-id=\"1862\"></path><path d=\"M674.834101 716.481939c-33.422222 4.90796-74.989899 16.884364-117.22602-8.102787-34.843152-20.613172-53.056646-20.993293-77.783919-18.49794-0.156444 0.015515-0.312889 0.015515-0.469334 0.034909-0.274101 0.033616-0.548202 0.060768-0.822303 0.094384-4.697212 0.487434-9.65301 1.065374-14.995394 1.62004-6.702545 0.649051-13.414141 1.19596-20.133495 1.634263-75.333818 4.102465-136.860444-5.381172-163.012525-10.404202-49.488162-9.872808-86.57196-23.921778-108.946101-33.970424-59.832889-26.868364-87.080081-56.671677-87.080081-72.989738 0-1.873455 0.384-2.222545 0.787394-2.585858 2.196687-1.974303 10.616242-6.520242 41.302626-6.004364 24.793212 0.418909 56.970343 3.858101 94.308849 7.853253 40.722101 4.348121 86.873212 9.283232 136.348444 11.686788 6.913293 0.333576 13.959758 0.625778 20.93899 0.858505 9.510788 0.307717 17.545051-7.182222 17.868283-16.707233 0.319354-9.535354-7.175758-17.550222-16.705939-17.868282a1386.24 1386.24 0 0 1-20.419233-0.839112c-48.521051-2.358303-94.161455-7.236525-134.434909-11.544565-90.868364-9.712485-139.353212-13.818828-162.333737 6.833131-8.02004 7.21196-12.262141 17.004606-12.262141 28.317737 0 0.672323 0.029737 1.348525 0.065939 2.026021l0.005172 0.100848c-0.045253 0.524929-0.071111 1.039515-0.071111 1.539879 0 41.464242 9.561212 81.661414 28.414707 119.484768 17.493333 35.088808 42.251636 66.663434 73.583192 93.927434 9.169455-6.551273 20.155475-13.604202 32.524929-20.050748 49.737697-25.921939 97.838545-29.339152 139.099798-9.884444 101.590626 47.906909 142.060606 47.837091 206.198949-0.364606 5.70699-4.287354 13.814949-3.140525 18.103596 2.567758 4.289939 5.708283 3.140525 13.813657-2.567757 18.103595-38.425859 28.877576-69.968162 41.279354-105.143596 41.280647-0.484848 0-0.969697-0.002586-1.457132-0.007758-32.760242-0.316768-69.311354-11.381657-126.16404-38.190545-51.905939-24.47903-106.215434 1.008485-139.548444 23.465374 64.611556 47.922424 146.341495 74.101657 232.704 74.101656 117.55701 0 226.204444-48.934788 292.761858-131.362909l0.002586-0.002586c18.79402-14.959192 12.028121-41.362101-23.442101-36.152889z\" fill=\"\" p-id=\"1863\"></path></svg>",
}
+2 -1
View File
@@ -75,7 +75,7 @@ var LatestVersion = map[string]string{}
//13. 支持更多的api接入示例
//`
var LatestVersionS = "v0.0.7"
var LatestVersionS = "v0.0.8"
var LatestVersionDesc = `
1. 单应用打包
2. 支持邮件发送
@@ -92,6 +92,7 @@ var LatestVersionDesc = `
13. 支持更多的api接入示例
14. 支持发送实例的暂停与开启
15. 支持企业微信消息发送
16. 支持站点信息自定义
`
func init() {
+2 -2
View File
@@ -21,7 +21,7 @@ func getFuncOutStr(funcStr string) string {
}
}
func CallerFormatter(funcStr string, fileStr string) string {
func CustomCallerFormatter(funcStr string, fileStr string) string {
fName := filepath.Base(fileStr)
funcOut := getFuncOutStr(funcStr)
return fmt.Sprintf(" [%s %s]", fName, funcOut)
@@ -35,7 +35,7 @@ func Setup() {
formatter.ForceColors = true
formatter.ForceFormatting = true
formatter.FullTimestamp = true
formatter.CallerFormatter = CallerFormatter
formatter.CallerFormatter = CustomCallerFormatter
formatter.TimestampFormat = "2006-01-02 15:04:05.000"
formatter.SetColorScheme(&prefixed.ColorScheme{
TimestampStyle: "cyan",
+24 -2
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"message-nest/pkg/app"
"message-nest/pkg/constant"
"message-nest/pkg/e"
"message-nest/service/settings_service"
"net/http"
@@ -93,11 +94,32 @@ func EditSettings(c *gin.Context) {
for key, value := range req.Data {
err := settingService.EditSettings(req.Section, key, value, currentUser)
if err != nil {
appG.CResponse(http.StatusBadRequest, fmt.Sprintf("修改密码失败!错误原因:%s", err), nil)
appG.CResponse(http.StatusBadRequest, fmt.Sprintf("修改站点设置失败!错误原因:%s", err), nil)
return
}
}
appG.CResponse(http.StatusOK, "修改成功!", nil)
appG.CResponse(http.StatusOK, "修改站点设置成功!", nil)
}
// RestDefaultSettings 重设默认设置
func RestDefaultSettings(c *gin.Context) {
var (
appG = app.Gin{C: c}
)
currentUser := app.GetCurrentUserName(c)
settingService := settings_service.UserSettings{}
for key, value := range constant.SiteSiteDefaultValueMap {
err := settingService.EditSettings(constant.SiteSettingSectionName, key, value, currentUser)
if err != nil {
appG.CResponse(http.StatusBadRequest, fmt.Sprintf("重设站点设置失败!错误原因:%s", err), nil)
return
}
}
appG.CResponse(http.StatusOK, "重设站点设置成功!", nil)
}
+1
View File
@@ -78,6 +78,7 @@ func InitRouter(f embed.FS) *gin.Engine {
// settings
apiV1.POST("/settings/setpasswd", v1.EditPasswd)
apiV1.POST("/settings/set", v1.EditSettings)
apiV1.POST("/settings/reset", v1.RestDefaultSettings)
apiV1.GET("/settings/getsetting", v1.GetUserSetting)
}
+10 -9
View File
@@ -10,12 +10,9 @@ import (
"message-nest/service/send_message_service"
)
type CronService struct {
}
var ClearLogsTaskId cron.EntryID
// 清除日志的定时任务
// ClearLogs 清除日志的定时任务
func ClearLogs() {
var errStr string
sm := send_message_service.SendMessageService{TaskID: constant.CleanLogsTaskId}
@@ -42,8 +39,11 @@ func ClearLogs() {
sm.RecordSendLog()
}
// 启动注册清除任务定时任务
func (cs *CronService) InitLogsCronRun() {
type CronService struct {
}
// StartLogsCronRun 启动注册清除任务定时任务
func (cs *CronService) StartLogsCronRun() {
// 注册任务
setting, err := models.GetSettingByKey(constant.LogsCleanSectionName, constant.LogsCleanCronKeyName)
if err != nil {
@@ -61,7 +61,7 @@ func (cs *CronService) InitLogsCronRun() {
}
}
// 更新清除任务定时任务
// UpdateLogsCronRun 更新清除任务定时任务
func (cs *CronService) UpdateLogsCronRun(cron string) {
RemoveTask(ClearLogsTaskId)
ClearLogsTaskId = AddTask(ScheduledTask{
@@ -73,7 +73,8 @@ func (cs *CronService) UpdateLogsCronRun(cron string) {
}
func Setup() {
// StartLogsCronRun 启动的时候开启定时任务
func StartLogsCronRun() {
cs := CronService{}
cs.InitLogsCronRun()
cs.StartLogsCronRun()
}
@@ -1,4 +1,4 @@
package env_service
package settings_service
import (
"github.com/sirupsen/logrus"
@@ -6,10 +6,11 @@ import (
"message-nest/pkg/constant"
)
type EnvService struct {
// 初始化环境的设置数据
type InitSettingService struct {
}
func (es *EnvService) CommonAdd(section string, key string, value string) {
func (es *InitSettingService) CommonAddSetting(section string, key string, value string) {
setting, _ := models.GetSettingByKey(section, key)
if setting.ID <= 0 {
err := models.AddOneSetting(models.Settings{
@@ -26,23 +27,17 @@ func (es *EnvService) CommonAdd(section string, key string, value string) {
}
// InitSiteConfig 初始化、重置站点信息设置
func (es *EnvService) InitSiteConfig() {
func (es *InitSettingService) InitSiteConfig() {
section := constant.SiteSettingSectionName
for key, value := range constant.SiteSiteDefaultValueMap {
es.CommonAdd(section, key, value)
es.CommonAddSetting(section, key, value)
}
}
// InitLogConfig 初始化日志清理设置
func (es *EnvService) InitLogConfig() {
func (es *InitSettingService) InitLogConfig() {
section := constant.LogsCleanSectionName
for key, value := range constant.LogsCleanDefaultValueMap {
es.CommonAdd(section, key, value)
es.CommonAddSetting(section, key, value)
}
}
func Setup() {
es := EnvService{}
es.InitSiteConfig()
es.InitLogConfig()
}
+3 -2
View File
@@ -4,10 +4,12 @@ import { ApiStrGenerate } from "@/util/viewApi.js";
// 定义一些常量名
const CONSTANT = {
PAGE: 1,
PAGE_SIZE: 8,
// PAGE_SIZE: 8,
TOTAL: 0,
DEFALUT_SITE_CONFIG: JSON.stringify({ "logo": "<svg t=\"1702547210136\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"1861\" width=\"200\" height=\"200\"><path d=\"M970.091313 224.033616a14.201535 14.201535 0 0 0-14.100687-3.631838c-88.419556-13.429657-142.919111-12.953859-248.242424 23.762747-69.454869 24.217859-109.056 79.873293-135.267556 116.712728-6.692202 9.403475-18.949172 26.625293-23.77309 29.509818-5.70699-1.303273-21.929374-16.036202-31.762101-24.965172-28.626747-25.994343-64.252121-58.353778-106.767516-58.757172-0.312889-0.005172-0.627071-0.005172-0.939959-0.005171-29.62101 0-54.798222 13.434828-72.857859 38.89907-13.222788 18.651798-17.914828 37.388929-18.106182 38.176323a14.31402 14.31402 0 0 0 2.893576 12.515556 14.336 14.336 0 0 0 11.782465 5.095434l0.409858-0.024565c19.192242-1.152 59.141172-3.545212 65.807516 81.857939 4.288646 54.899071 29.742545 108.631919 69.833697 147.419798 45.499475 44.025535 106.237414 67.298263 175.650909 67.298263 98.97503 0 166.222869-24.480323 205.207272-45.015919 43.172202-22.742626 62.621737-45.918384 63.429819-46.898425a14.170505 14.170505 0 0 0 1.529535-15.874586 14.191192 14.191192 0 0 0-14.166626-7.337373c-37.924202 4.443798-92.767677 6.09099-138.666667-11.298909-7.580444-2.872889-13.878303-5.893172-18.959515-8.691071 20.273131-9.964606 51.000889-28.383677 83.621495-59.93503 34.186343-33.065374 37.722505-69.908687 40.838464-102.423273 2.297535-23.919192 4.666182-48.651636 18.500526-73.091879 28.807758-50.883232 66.645333-74.489535 74.560646-79.035475a14.201535 14.201535 0 0 0 12.135434-7.776969 14.193778 14.193778 0 0 0-2.59103-16.484849z\" fill=\"\" p-id=\"1862\"></path><path d=\"M674.834101 716.481939c-33.422222 4.90796-74.989899 16.884364-117.22602-8.102787-34.843152-20.613172-53.056646-20.993293-77.783919-18.49794-0.156444 0.015515-0.312889 0.015515-0.469334 0.034909-0.274101 0.033616-0.548202 0.060768-0.822303 0.094384-4.697212 0.487434-9.65301 1.065374-14.995394 1.62004-6.702545 0.649051-13.414141 1.19596-20.133495 1.634263-75.333818 4.102465-136.860444-5.381172-163.012525-10.404202-49.488162-9.872808-86.57196-23.921778-108.946101-33.970424-59.832889-26.868364-87.080081-56.671677-87.080081-72.989738 0-1.873455 0.384-2.222545 0.787394-2.585858 2.196687-1.974303 10.616242-6.520242 41.302626-6.004364 24.793212 0.418909 56.970343 3.858101 94.308849 7.853253 40.722101 4.348121 86.873212 9.283232 136.348444 11.686788 6.913293 0.333576 13.959758 0.625778 20.93899 0.858505 9.510788 0.307717 17.545051-7.182222 17.868283-16.707233 0.319354-9.535354-7.175758-17.550222-16.705939-17.868282a1386.24 1386.24 0 0 1-20.419233-0.839112c-48.521051-2.358303-94.161455-7.236525-134.434909-11.544565-90.868364-9.712485-139.353212-13.818828-162.333737 6.833131-8.02004 7.21196-12.262141 17.004606-12.262141 28.317737 0 0.672323 0.029737 1.348525 0.065939 2.026021l0.005172 0.100848c-0.045253 0.524929-0.071111 1.039515-0.071111 1.539879 0 41.464242 9.561212 81.661414 28.414707 119.484768 17.493333 35.088808 42.251636 66.663434 73.583192 93.927434 9.169455-6.551273 20.155475-13.604202 32.524929-20.050748 49.737697-25.921939 97.838545-29.339152 139.099798-9.884444 101.590626 47.906909 142.060606 47.837091 206.198949-0.364606 5.70699-4.287354 13.814949-3.140525 18.103596 2.567758 4.289939 5.708283 3.140525 13.813657-2.567757 18.103595-38.425859 28.877576-69.968162 41.279354-105.143596 41.280647-0.484848 0-0.969697-0.002586-1.457132-0.007758-32.760242-0.316768-69.311354-11.381657-126.16404-38.190545-51.905939-24.47903-106.215434 1.008485-139.548444 23.465374 64.611556 47.922424 146.341495 74.101657 232.704 74.101656 117.55701 0 226.204444-48.934788 292.761858-131.362909l0.002586-0.002586c18.79402-14.959192 12.028121-41.362101-23.442101-36.152889z\" fill=\"\" p-id=\"1863\"></path></svg>", "pagesize": "8", "slogan": "A Message Way Hosted Site", "title": "Message Nest" }),
LOG_TASK_ID: "00000000-0000-0000-0000-000000000001",
STORE_TOKEN_NAME: '__message_nest_token__',
STORE_CUSTOM_NAME: '__message_nest_custom_site__',
NO_AUTH_URL: [
'/auth',
],
@@ -83,7 +85,6 @@ const CONSTANT = {
],
},
],
LOGO: `<svg t="1702547210136" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1861" width="200" height="200"><path d="M970.091313 224.033616a14.201535 14.201535 0 0 0-14.100687-3.631838c-88.419556-13.429657-142.919111-12.953859-248.242424 23.762747-69.454869 24.217859-109.056 79.873293-135.267556 116.712728-6.692202 9.403475-18.949172 26.625293-23.77309 29.509818-5.70699-1.303273-21.929374-16.036202-31.762101-24.965172-28.626747-25.994343-64.252121-58.353778-106.767516-58.757172-0.312889-0.005172-0.627071-0.005172-0.939959-0.005171-29.62101 0-54.798222 13.434828-72.857859 38.89907-13.222788 18.651798-17.914828 37.388929-18.106182 38.176323a14.31402 14.31402 0 0 0 2.893576 12.515556 14.336 14.336 0 0 0 11.782465 5.095434l0.409858-0.024565c19.192242-1.152 59.141172-3.545212 65.807516 81.857939 4.288646 54.899071 29.742545 108.631919 69.833697 147.419798 45.499475 44.025535 106.237414 67.298263 175.650909 67.298263 98.97503 0 166.222869-24.480323 205.207272-45.015919 43.172202-22.742626 62.621737-45.918384 63.429819-46.898425a14.170505 14.170505 0 0 0 1.529535-15.874586 14.191192 14.191192 0 0 0-14.166626-7.337373c-37.924202 4.443798-92.767677 6.09099-138.666667-11.298909-7.580444-2.872889-13.878303-5.893172-18.959515-8.691071 20.273131-9.964606 51.000889-28.383677 83.621495-59.93503 34.186343-33.065374 37.722505-69.908687 40.838464-102.423273 2.297535-23.919192 4.666182-48.651636 18.500526-73.091879 28.807758-50.883232 66.645333-74.489535 74.560646-79.035475a14.201535 14.201535 0 0 0 12.135434-7.776969 14.193778 14.193778 0 0 0-2.59103-16.484849z" fill="" p-id="1862"></path><path d="M674.834101 716.481939c-33.422222 4.90796-74.989899 16.884364-117.22602-8.102787-34.843152-20.613172-53.056646-20.993293-77.783919-18.49794-0.156444 0.015515-0.312889 0.015515-0.469334 0.034909-0.274101 0.033616-0.548202 0.060768-0.822303 0.094384-4.697212 0.487434-9.65301 1.065374-14.995394 1.62004-6.702545 0.649051-13.414141 1.19596-20.133495 1.634263-75.333818 4.102465-136.860444-5.381172-163.012525-10.404202-49.488162-9.872808-86.57196-23.921778-108.946101-33.970424-59.832889-26.868364-87.080081-56.671677-87.080081-72.989738 0-1.873455 0.384-2.222545 0.787394-2.585858 2.196687-1.974303 10.616242-6.520242 41.302626-6.004364 24.793212 0.418909 56.970343 3.858101 94.308849 7.853253 40.722101 4.348121 86.873212 9.283232 136.348444 11.686788 6.913293 0.333576 13.959758 0.625778 20.93899 0.858505 9.510788 0.307717 17.545051-7.182222 17.868283-16.707233 0.319354-9.535354-7.175758-17.550222-16.705939-17.868282a1386.24 1386.24 0 0 1-20.419233-0.839112c-48.521051-2.358303-94.161455-7.236525-134.434909-11.544565-90.868364-9.712485-139.353212-13.818828-162.333737 6.833131-8.02004 7.21196-12.262141 17.004606-12.262141 28.317737 0 0.672323 0.029737 1.348525 0.065939 2.026021l0.005172 0.100848c-0.045253 0.524929-0.071111 1.039515-0.071111 1.539879 0 41.464242 9.561212 81.661414 28.414707 119.484768 17.493333 35.088808 42.251636 66.663434 73.583192 93.927434 9.169455-6.551273 20.155475-13.604202 32.524929-20.050748 49.737697-25.921939 97.838545-29.339152 139.099798-9.884444 101.590626 47.906909 142.060606 47.837091 206.198949-0.364606 5.70699-4.287354 13.814949-3.140525 18.103596 2.567758 4.289939 5.708283 3.140525 13.813657-2.567757 18.103595-38.425859 28.877576-69.968162 41.279354-105.143596 41.280647-0.484848 0-0.969697-0.002586-1.457132-0.007758-32.760242-0.316768-69.311354-11.381657-126.16404-38.190545-51.905939-24.47903-106.215434 1.008485-139.548444 23.465374 64.611556 47.922424 146.341495 74.101657 232.704 74.101656 117.55701 0 226.204444-48.934788 292.761858-131.362909l0.002586-0.002586c18.79402-14.959192 12.028121-41.362101-23.442101-36.152889z" fill="" p-id="1863"></path></svg>`,
API_VIEW_DATA: [
{ label: "curl", class: "language-shell line-numbers", code: "", func: ApiStrGenerate.getCurlString },
{ label: "python", class: "language-python line-numbers", code: "", func: ApiStrGenerate.getPythonString },
+3
View File
@@ -1,5 +1,7 @@
import { defineStore } from 'pinia';
import { LocalStieConfigUtils } from '@/util/localSiteConfig'
export const usePageState = defineStore({
id: 'pageState',
@@ -7,6 +9,7 @@ export const usePageState = defineStore({
isLogin: false, // 全局的登录状态
Token: '', // 全局的登录状态
isShowAddWayDialog: false,
siteConfigData: LocalStieConfigUtils.getLocalConfig(),
ShowDialogData: {}
}),
actions: {
+37
View File
@@ -0,0 +1,37 @@
import { CONSTANT } from '@/constant'
import { request } from '@/api/api'
class LocalStieConfigUtils {
// 更新本地的site设置
static updateLocalConfig = (data) => {
localStorage.setItem(CONSTANT.STORE_CUSTOM_NAME, JSON.stringify(data));
}
// 更新本地的site设置
static getLocalConfig = () => {
let d = localStorage.getItem(CONSTANT.STORE_CUSTOM_NAME);
if (!d) {
d = CONSTANT.DEFALUT_SITE_CONFIG;
}
let data = JSON.parse(d);
data.pagesize = Number(data.pagesize);
return data
}
// 获取最新的本地的site设置
static getLatestLocalConfig = async () => {
let params = { params: { section: "site_config" } };
const rsp = await request.get('/settings/getsetting', params);
if (await rsp.data.code == 200) {
let data = await rsp.data.data;
LocalStieConfigUtils.updateLocalConfig(data);
}
return LocalStieConfigUtils.getLocalConfig();
}
}
export { LocalStieConfigUtils };
+13 -2
View File
@@ -3,6 +3,7 @@
<el-menu :collapse="isCollapse" breakpoint="768px" mode="horizontal" @select="handleSelect()"
:default-active="currActivate()" :ellipsis="false" :menu-width="'auto'">
<el-menu-item index="0" :disabled="false">
<!-- <div class="title-logo" v-html="titleLogo"></div> -->
<img style="width: 60px" class="title-logo" :src="titleLogo" alt="Message logo" />
</el-menu-item>
@@ -30,7 +31,7 @@ export default {
const router = useRouter();
const isCollapse = ref(false);
const state = reactive({
titleLogo: 'data:image/svg+xml;utf8,' + CONSTANT.LOGO,
titleLogo: '',
});
const menuData = reactive([
{
@@ -76,10 +77,16 @@ export default {
return result;
}
const setSiteConfig = () => {
document.title = pageState.siteConfigData.title;
state.titleLogo = 'data:image/svg+xml;base64,' + btoa(pageState.siteConfigData.logo);
}
onMounted(() => {
changeFavicon();
checkIsLogin();
loadLocalToken();
setSiteConfig();
});
const changeFavicon = () => {
@@ -87,7 +94,7 @@ export default {
if (link) {
link.type = 'image/svg+xml';
link.rel = 'icon';
link.href = 'data:image/svg+xml;utf8,' + CONSTANT.LOGO;
link.href = 'data:image/svg+xml;base64,' + btoa(pageState.siteConfigData.logo)
document.getElementsByTagName('head')[0].appendChild(link);
}
}
@@ -118,6 +125,10 @@ export default {
margin: 0 auto;
}
.title-logo svg {
height: 50px;
}
.logout-btn {
margin: auto 40px auto 40px;
float: right;
+9 -5
View File
@@ -4,7 +4,7 @@
<div class="main-center-body">
<div class="container">
<img class="login-logo" :src="logo" alt="login logo">
<p class="desc">A Message Way Hosted Site</p>
<p class="desc">{{ slogan }}</p>
<div class="login-block">
<p class="login-text">账号</p>
@@ -33,21 +33,25 @@ import { request } from '../../api/api'
import { CONSTANT } from '../../constant'
import { usePageState } from '../../store/page_sate';
import { useRouter } from 'vue-router';
import { LocalStieConfigUtils } from '@/util/localSiteConfig'
export default {
setup() {
const router = useRouter();
const pageState = usePageState();
const state = reactive({
account: '',
passwd: '',
logo: 'data:image/svg+xml;utf8,' + CONSTANT.LOGO,
logo: 'data:image/svg+xml;base64,' + btoa(pageState.siteConfigData.logo),
slogan: pageState.siteConfigData.slogan,
});
onMounted(() => {
// 加载站点信息
setTimeout(() => {
LocalStieConfigUtils.getLatestLocalConfig();
}, 100)
});
// 登录
@@ -60,7 +64,7 @@ export default {
pageState.setToken(rsp.data.token);
pageState.setIsLogin(true);
localStorage.setItem(CONSTANT.STORE_TOKEN_NAME, rsp.data.token);
router.push('/sendlogs', { replace: true })
router.push('/sendlogs', { replace: true });
}
};
@@ -37,7 +37,7 @@
<div class="pagination-block">
<el-pagination layout="prev, pager, next" :total="total" :page-size="pageSize" @current-change="handPageChange" />
<el-text class="total-tip" size="small">{{ total }}</el-text>
<el-text class="total-tip" size="small">每页{{ pageSize }}{{ total }}</el-text>
</div>
</div>
@@ -50,11 +50,13 @@ import { request } from '../../../api/api'
import { copyToClipboard } from '../../../util/clipboard.js';
import { useRoute } from 'vue-router';
import { CONSTANT } from '@/constant'
import { usePageState } from '@/store/page_sate.js';
export default {
components: {
},
setup() {
const pageState = usePageState();
const router = useRoute();
const state = reactive({
search: '',
@@ -63,7 +65,7 @@ export default {
drawer: false,
tableData: [],
total: CONSTANT.TOTAL,
pageSize: CONSTANT.PAGE_SIZE,
pageSize: pageState.siteConfigData.pagesize,
currPage: CONSTANT.PAGE,
});
@@ -38,7 +38,7 @@
<div class="pagination-block">
<el-pagination layout="prev, pager, next" :total="total" :page-size="pageSize" @current-change="handPageChange" />
<el-text class="total-tip" size="small">{{ total }}</el-text>
<el-text class="total-tip" size="small">每页{{ pageSize }}{{ total }}</el-text>
</div>
</div>
@@ -83,7 +83,7 @@ export default {
// confirmBtnVisible: false,
tableData: [],
total: CONSTANT.TOTAL,
pageSize: CONSTANT.PAGE_SIZE,
pageSize: pageState.siteConfigData.pagesize,
currPage: CONSTANT.PAGE,
displayCols: [
{ 'col': 'id', 'label': '任务ID' },
@@ -43,7 +43,7 @@
</div>
<div class="pagination-block">
<el-pagination layout="prev, pager, next" :total="total" :page-size="pageSize" @current-change="handPageChange" />
<el-text class="total-tip" size="small">{{ total }}</el-text>
<el-text class="total-tip" size="small">每页{{ pageSize }}{{ total }}</el-text>
</div>
<addWayComponent :componentName="addWayComponentName" />
@@ -83,7 +83,7 @@ export default {
// confirmBtnVisible: false,
tableData: [],
total: CONSTANT.TOTAL,
pageSize: CONSTANT.PAGE_SIZE,
pageSize: pageState.siteConfigData.pagesize,
currPage: CONSTANT.PAGE,
displayCols: [
{ 'col': 'id', 'label': '渠道ID' },
@@ -10,9 +10,9 @@
<el-menu-item index="logCleanSetting">
日志清理
</el-menu-item>
<!-- <el-menu-item index="siteCustomSetting">
<el-menu-item index="siteCustomSetting">
站点设置
</el-menu-item> -->
</el-menu-item>
<el-menu-item index="aboutSetting">
站点关于
</el-menu-item>
@@ -82,9 +82,9 @@ hr {
margin-top: -10vh;
}
/* .setting-main {
} */
:deep(.el-input ) {
margin-top: 14px;
}
.setting-right {
width: 100%;
@@ -4,12 +4,15 @@
<el-input v-model="title" size="small" placeholder="请输入自定义的网站标题">
<template size="small" #prepend>站点标题</template>
</el-input>
<el-input v-model.number="slogan" size="small" placeholder="请输入自定义的网站slogan" style="margin-top: 15px;">
<el-input v-model="slogan" size="small" placeholder="请输入自定义的网站slogan">
<template size="small" #prepend>站点标语</template>
</el-input>
<el-input v-model.number="logo" size="small" placeholder="请输入自定义的网站logosvg文本)" style="margin-top: 15px;">
<el-input v-model="logo" size="small" placeholder="请输入自定义的网站logosvg文本)">
<template size="small" #prepend>站点图标</template>
</el-input>
<el-input v-model="pagesize" size="small" placeholder="页面分页大小">
<template size="small" #prepend>分页大小</template>
</el-input>
</div>
<div class="buttom">
<div class="tips">
@@ -27,7 +30,7 @@
</el-icon>
</el-tooltip>
</div>
<el-button @click="handleView" size="small">恢复默认</el-button>
<el-button @click="handleSubmitReset" size="small">恢复默认</el-button>
<el-button @click="handleSubmit" size="small" type="primary">确定</el-button>
</div>
</div>
@@ -40,6 +43,8 @@ import { QuestionFilled } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router';
import { request } from '@/api/api'
import { CONSTANT } from '@/constant'
import { LocalStieConfigUtils } from '@/util/localSiteConfig'
export default defineComponent({
components: {
@@ -55,6 +60,7 @@ export default defineComponent({
title: '',
slogan: '',
logo: '',
pagesize: '',
section: 'site_config',
});
@@ -65,6 +71,7 @@ export default defineComponent({
title: state.title.trim(),
slogan: state.slogan.trim(),
logo: state.logo.trim(),
pagesize: state.pagesize,
},
};
const rsp = await request.post('/settings/set', postData);
@@ -73,8 +80,15 @@ export default defineComponent({
ElMessage({ message: msg, type: 'success' })
}
}
const handleView = async () => {
router.push('/sendlogs?taskid=' + CONSTANT.LOG_TASK_ID, { replace: true });
const handleSubmitReset = async () => {
const rsp = await request.post('/settings/reset', {});
if (await rsp.data.code == 200) {
let msg = await rsp.data.msg;
ElMessage({ message: msg, type: 'success' });
// 重新获取设置
await getSiteConfig();
}
}
const getSiteConfig = async () => {
@@ -85,6 +99,9 @@ export default defineComponent({
state.title = data.title;
state.logo = data.logo;
state.slogan = data.slogan;
state.pagesize = data.pagesize;
LocalStieConfigUtils.updateLocalConfig(data);
}
}
@@ -93,7 +110,7 @@ export default defineComponent({
})
return {
...toRefs(state), handleSubmit, handleView
...toRefs(state), handleSubmit, handleSubmitReset
}
}