-
Notifications
You must be signed in to change notification settings - Fork 0
/
val.go
69 lines (67 loc) · 1.9 KB
/
val.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package ERPCore
import (
"fmt"
BaseFileSys2 "github.com/fotomxq/weeekj_core/v5/base/filesys2"
CoreFilter "github.com/fotomxq/weeekj_core/v5/core/filter"
CoreLanguage "github.com/fotomxq/weeekj_core/v5/core/language"
"github.com/gin-gonic/gin"
)
// GetValOfType 获取组件的值,并解析为指定的类型
// 注意反馈为any泛型,可直接转为对应类型
// isShow 将转化为可直接显示的数据,例如bool为是否,而不是true/false
func GetValOfType(ctx *gin.Context, data *FieldsComponentVal, isShow bool) (result any) {
switch data.ComponentType {
case "number_int":
//数字
result = CoreFilter.GetInt64ByStringNoErr(data.Val)
case "number_float":
//浮点数
result = CoreFilter.GetFloat64ByStringNoErr(data.Val)
case "number_price":
//价格数据
if isShow {
result = float64(CoreFilter.GetInt64ByStringNoErr(data.Val)) / 100
} else {
result = CoreFilter.GetInt64ByStringNoErr(data.Val)
}
case "number_p":
//百分比数据
if isShow {
result = fmt.Sprint(float64(CoreFilter.GetInt64ByStringNoErr(data.Val))/100, "%")
} else {
result = CoreFilter.GetInt64ByStringNoErr(data.Val)
}
case "bool_open":
//bool值
if isShow {
if CoreFilter.GetBoolByInterfaceNoErr(data.Val) {
result = CoreLanguage.GetLanguageText(ctx, "bool_true")
} else {
result = CoreLanguage.GetLanguageText(ctx, "bool_false")
}
} else {
result = CoreFilter.GetBoolByInterfaceNoErr(data.Val)
}
case "file_id":
//文件URL
fileID := CoreFilter.GetInt64ByStringNoErr(data.Val)
if fileID > 0 {
result = BaseFileSys2.GetPublicURLByClaimID(fileID)
} else {
result = ""
}
case "file_ids":
//文件URL
fileIDs := CoreFilter.GetIDsInString(data.Val, ",")
if len(fileIDs) > 0 {
for k := 0; k < len(fileIDs); k++ {
result = BaseFileSys2.GetPublicURLByClaimID(fileIDs[k])
}
} else {
result = ""
}
default:
result = data.Val
}
return
}