u
This commit is contained in:
1 parent
50fdacac07
commit
48cd564201
13 files changed
+204
-106
No files matched your search
Generated
File renamed without changes.
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/base-farmework.iml" filepath="$PROJECT_DIR$/.idea/base-farmework.iml" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/base-go.iml" filepath="$PROJECT_DIR$/.idea/base-go.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -5,12 +5,35 @@ import (
|
|||||||
"base-framework/pkg/router"
|
"base-framework/pkg/router"
|
||||||
"base-framework/pkg/routinex"
|
"base-framework/pkg/routinex"
|
||||||
"base-framework/pkg/utils/uid"
|
"base-framework/pkg/utils/uid"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TrackTime 记录开始时间到现在时间的耗时
|
||||||
|
func TrackTime(pre time.Time) time.Duration {
|
||||||
|
elapsed := time.Since(pre)
|
||||||
|
|
||||||
|
return elapsed
|
||||||
|
}
|
||||||
|
|
||||||
func Logger() router.HandlerFunc {
|
func Logger() router.HandlerFunc {
|
||||||
return func(c *router.Context) {
|
return func(c *router.Context) {
|
||||||
routinex.Set(logx.TrackID, uid.NextID())
|
start := time.Now() // 记录开始时间
|
||||||
|
|
||||||
c.Next()
|
// 生成 trackID 并存入 routinex
|
||||||
|
trackID := uid.NextID()
|
||||||
|
routinex.Set(logx.TrackID, trackID)
|
||||||
|
|
||||||
|
c.Next() // 执行业务逻辑
|
||||||
|
|
||||||
|
// 请求结束后计算耗时
|
||||||
|
elapsed := TrackTime(start)
|
||||||
|
|
||||||
|
logx.Logger.Info("请求结束",
|
||||||
|
logx.String("logType", "request"),
|
||||||
|
logx.Uint64("trackID", trackID),
|
||||||
|
logx.String("path", c.Request.URL.Path),
|
||||||
|
logx.String("method", c.Request.Method),
|
||||||
|
logx.Duration("elapsed", elapsed),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
保证多routine共用同一数据
|
||||||
|
*/
|
||||||
|
|
||||||
package routinex
|
package routinex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -7,7 +11,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ------------------- goroutine id -------------------
|
// CurGID 获取 routine 的id
|
||||||
func CurGID() uint64 {
|
func CurGID() uint64 {
|
||||||
var buf [64]byte
|
var buf [64]byte
|
||||||
n := runtime.Stack(buf[:], false)
|
n := runtime.Stack(buf[:], false)
|
||||||
@@ -25,6 +29,7 @@ var (
|
|||||||
instanceOnce sync.Once
|
instanceOnce sync.Once
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetInstance 获取当前示例
|
||||||
func GetInstance() *RoutineLocal {
|
func GetInstance() *RoutineLocal {
|
||||||
instanceOnce.Do(func() {
|
instanceOnce.Do(func() {
|
||||||
instance = &RoutineLocal{}
|
instance = &RoutineLocal{}
|
||||||
@@ -57,7 +62,7 @@ func Clear() {
|
|||||||
GetInstance().data.Delete(CurGID())
|
GetInstance().data.Delete(CurGID())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go 封装函数,自动继承父 goroutine 数据
|
// Go 自动继承父 goroutine 数据,多 routine 的时候需要使用
|
||||||
func Go(f func()) {
|
func Go(f func()) {
|
||||||
parentGID := CurGID()
|
parentGID := CurGID()
|
||||||
parentData, _ := GetInstance().data.Load(parentGID)
|
parentData, _ := GetInstance().data.Load(parentGID)
|
||||||
|
|||||||
@@ -1,103 +1,109 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Material ui 水波纹效果</title>
|
<title>后台按钮渐深点击升级版</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<link rel="shortcut icon" href="#" />
|
|
||||||
<script src="https://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>
|
|
||||||
</head>
|
|
||||||
<style>
|
<style>
|
||||||
button {
|
body {
|
||||||
display: block; /* button 默认是inline-block 无法用margin给它居中 */
|
font-family: Arial, sans-serif;
|
||||||
margin: 50px auto;
|
padding: 20px;
|
||||||
height: 60px;
|
background: #f8f9fa;
|
||||||
width: 150px;
|
}
|
||||||
|
.btn-group {
|
||||||
|
padding: 16px;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 6px;
|
||||||
|
min-width: 280px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 基础按钮 */
|
||||||
|
.admin-btn {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 6px 14px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 16px;
|
margin: 0 6px 6px 0;
|
||||||
background: #e95546;
|
|
||||||
outline: none;
|
outline: none;
|
||||||
border: 0;
|
transition: filter 0.2s ease;
|
||||||
cursor: pointer; /* 为了增加用户体验 */
|
|
||||||
|
|
||||||
position: relative; /* 为了保持和ripple的位置关系 */
|
|
||||||
overflow: hidden; /* 为了遮盖超出的ripple */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.ripple {
|
/* 按钮颜色和overlay变量 */
|
||||||
position: absolute; /* 为了保持和button的位置关系 */
|
.btn-primary {
|
||||||
border-radius: 50% 50%; /* 水波纹圆形 */
|
background-color: #2563eb;
|
||||||
background: rgba(255, 255, 255, 0.4); /* 水波纹颜色 */
|
--overlay-color: rgba(0, 0, 0, 0.22);
|
||||||
|
}
|
||||||
/* 下面与动画效果相关 是0%时候的状态 */
|
.btn-secondary {
|
||||||
/* 默认的 transform-origin 是 center 即中心点 */
|
background-color: #1f2937;
|
||||||
transform: scale(0);
|
--overlay-color: rgba(255, 255, 255, 0.12);
|
||||||
-webkit-transform: scale(0);
|
}
|
||||||
opacity: 1;
|
.btn-danger {
|
||||||
|
background-color: #ef4444;
|
||||||
|
--overlay-color: rgba(0, 0, 0, 0.18);
|
||||||
}
|
}
|
||||||
|
|
||||||
.rippleEffect {
|
/* hover变浅 */
|
||||||
/* 执行时长0.6s、效果为渐变(linear)、名称为rippleDrop的动画 */
|
.admin-btn:hover {
|
||||||
-webkit-animation: rippleDrop 0.6s linear;
|
filter: brightness(1.1);
|
||||||
animation: rippleDrop 0.6s linear;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes rippleDrop {
|
/* 点击渐深叠加层 */
|
||||||
/* 下面是动画100%时候的状态 */
|
.admin-btn::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 0;
|
||||||
|
height: 100%;
|
||||||
|
background: linear-gradient(to right, rgba(0, 0, 0, 0), var(--overlay-color), rgba(0, 0, 0, 0));
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 点击触发动画 */
|
||||||
|
.admin-btn.active::after {
|
||||||
|
animation: tideDeep 0.35s ease-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes tideDeep {
|
||||||
|
0% {
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
100% {
|
100% {
|
||||||
transform: scale(2);
|
width: 100%;
|
||||||
-webkit-transform: scale(2);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@-webkit-keyframes rippleDrop {
|
|
||||||
100% {
|
|
||||||
transform: scale(2);
|
|
||||||
-webkit-transform: scale(2);
|
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div class="btn-group">
|
||||||
<button>这是一个按钮</button>
|
<button class="admin-btn btn-primary">保存修改</button>
|
||||||
|
<button class="admin-btn btn-secondary">取消</button>
|
||||||
|
<button class="admin-btn btn-danger">删除</button>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
$('button').click(function (e) {
|
document.querySelectorAll('.admin-btn').forEach((btn) => {
|
||||||
$('.ripple').remove() // 每次先把之前添加的水波纹div删除
|
btn.addEventListener('click', () => {
|
||||||
|
if (btn.classList.contains('active')) return
|
||||||
let button_left = $(this).offset().left // button距离页面左边的距离
|
btn.classList.add('active')
|
||||||
let button_top = $(this).offset().top // button距离页面上边的距离
|
btn.addEventListener(
|
||||||
let button_width = $(this).width() // button的宽度
|
'animationend',
|
||||||
let button_height = $(this).height() // button的高度
|
() => {
|
||||||
|
btn.classList.remove('active')
|
||||||
// 水波纹div为一个圆形,使得它的半径等于button的最长边,故在这里计算最长边是多少
|
},
|
||||||
let ripple_width = 0
|
{ once: true },
|
||||||
ripple_width = button_width > button_height ? button_width : button_height
|
)
|
||||||
|
|
||||||
// e.pageX是click事件的鼠标触发点距离页面左边的距离
|
|
||||||
// e.pageY是click事件的鼠标触发点距离页面上边的距离
|
|
||||||
// 这里的算法是,算出鼠标点击点的坐标为 (e.pageX - button_left, e.pageY - button_top)
|
|
||||||
// 但是由于`transform-origin`默认是center,所以这里再减去半径才是div应该的位置
|
|
||||||
let ripple_x = e.pageX - button_left - ripple_width / 2
|
|
||||||
let ripple_y = e.pageY - button_top - ripple_width / 2
|
|
||||||
|
|
||||||
// 往button里面塞水波纹div
|
|
||||||
$(this).prepend("<div class='ripple'></div>")
|
|
||||||
|
|
||||||
// 给水波纹div应用样式和动画
|
|
||||||
$('.ripple')
|
|
||||||
.css({
|
|
||||||
width: ripple_width + 'px',
|
|
||||||
height: ripple_width + 'px',
|
|
||||||
top: ripple_y + 'px',
|
|
||||||
left: ripple_x + 'px',
|
|
||||||
})
|
})
|
||||||
.addClass('rippleEffect')
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+27
-22
@@ -4,7 +4,9 @@
|
|||||||
<option name="autoReloadType" value="ALL" />
|
<option name="autoReloadType" value="ALL" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="4636f4cb-d351-4483-ab41-f250e36fd785" name="更改" comment="" />
|
<list default="true" id="4636f4cb-d351-4483-ab41-f250e36fd785" name="更改" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/../../base-project/base-vue/test.html" beforeDir="false" afterPath="$PROJECT_DIR$/../../base-project/base-vue/test.html" afterDir="false" />
|
||||||
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
@@ -32,26 +34,29 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"DefaultGoTemplateProperty": "Go File",
|
"DefaultGoTemplateProperty": "Go File",
|
||||||
"Go Build.go build base-framework/cmd/app.executor": "Run",
|
"Go Build.go build base-framework/cmd/app.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
"RunOnceActivity.GoLinterPluginOnboarding": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.GoLinterPluginStorageMigration": "true",
|
||||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"git-widget-placeholder": "master",
|
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||||
"go.import.settings.migrated": "true",
|
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||||
"last_opened_file_path": "C:/Users/oneao",
|
"git-widget-placeholder": "master",
|
||||||
"node.js.detected.package.eslint": "true",
|
"go.import.settings.migrated": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"nodejs_package_manager_path": "npm",
|
"last_opened_file_path": "C:/Users/Administrator",
|
||||||
"settings.editor.selected.configurable": "com.goide.configuration.GoLibrariesConfigurableProvider"
|
"node.js.detected.package.eslint": "true",
|
||||||
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
|
"nodejs_package_manager_path": "npm",
|
||||||
|
"settings.editor.selected.configurable": "com.goide.configuration.GoLibrariesConfigurableProvider"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="CopyFile.RECENT_KEYS">
|
<key name="CopyFile.RECENT_KEYS">
|
||||||
<recent name="D:\workspace\code\go-project\base-farmework\pkg\configs" />
|
<recent name="D:\workspace\code\go-project\base-farmework\pkg\configs" />
|
||||||
@@ -81,8 +86,8 @@
|
|||||||
<component name="SharedIndexes">
|
<component name="SharedIndexes">
|
||||||
<attachedChunks>
|
<attachedChunks>
|
||||||
<set>
|
<set>
|
||||||
<option value="bundled-gosdk-f466f9b0953e-3d2cccfc42a2-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-252.23892.449" />
|
<option value="bundled-gosdk-3b128438d3f6-07d2d2d66b1e-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-251.27812.54" />
|
||||||
<option value="bundled-js-predefined-d6986cc7102b-e03c56caf84a-JavaScript-GO-252.23892.449" />
|
<option value="bundled-js-predefined-d6986cc7102b-09060db00ec0-JavaScript-GO-251.27812.54" />
|
||||||
</set>
|
</set>
|
||||||
</attachedChunks>
|
</attachedChunks>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/demo-project.iml" filepath="$PROJECT_DIR$/.idea/demo-project.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
module demo-project
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
//TIP <p>To run your code, right-click the code and select <b>Run</b>.</p> <p>Alternatively, click
|
||||||
|
// the <icon src="AllIcons.Actions.Execute"/> icon in the gutter and select the <b>Run</b> menu item from here.</p>
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
//TIP <p>Press <shortcut actionId="ShowIntentionActions"/> when your caret is at the underlined text
|
||||||
|
// to see how GoLand suggests fixing the warning.</p><p>Alternatively, if available, click the lightbulb to view possible fixes.</p>
|
||||||
|
s := "gopher"
|
||||||
|
fmt.Printf("Hello and welcome, %s!\n", s)
|
||||||
|
|
||||||
|
for i := 1; i <= 5; i++ {
|
||||||
|
//TIP <p>To start your debugging session, right-click your code in the editor and select the Debug option.</p> <p>We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||||
|
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.</p>
|
||||||
|
fmt.Println("i =", 100/i)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user