Files
tianrunCRM/Assets/trCRM/upgradeRes4Dev/priority/lua/toolkit/MyUtl.lua

170 lines
4.9 KiB
Lua
Raw Normal View History

2020-07-04 14:41:25 +08:00
MyUtl = {}
2020-08-01 17:55:18 +08:00
MyUtl.dampenStrength = 3 -- 惯性阻力
2020-07-04 14:41:25 +08:00
MyUtl.init = function(panel)
MyUtl.getUIContent(panel)
end
2020-08-04 21:58:27 +08:00
MyUtl.defaultTopHeight = 132
MyUtl.defaultBottomHeight = 147
2020-07-04 14:41:25 +08:00
local _ContentRect
local _sizeAdjust
2020-07-26 11:12:32 +08:00
---@return UnityEngine.Vector4
2020-07-04 14:41:25 +08:00
MyUtl.getUIContent = function(panel, top, bottom, forceCal)
-- if _ContentRect and (not forceCal) then
-- return _ContentRect
-- end
2020-07-11 10:57:19 +08:00
local sizeAdjust = UIRoot.GetPixelSizeAdjustment(panel.gameObject)
local height = Screen.height * sizeAdjust
2020-08-04 21:58:27 +08:00
top = top or MyUtl.defaultTopHeight
bottom = bottom or MyUtl.defaultBottomHeight
2020-07-11 10:57:19 +08:00
local offsetRect = NGUITools.offsetRect
top = top + offsetRect.y * height
bottom = bottom + offsetRect.w * height
2020-07-04 14:41:25 +08:00
_sizeAdjust = sizeAdjust
2020-07-11 10:57:19 +08:00
_ContentRect = Vector4(0, (bottom - top) / 2, Screen.width * sizeAdjust, height - (bottom + top))
2020-07-04 14:41:25 +08:00
return _ContentRect
end
MyUtl.setContentView = function(go, top, bottom)
local panel = go:GetComponent("UIPanel")
if panel then
panel.transform.localPosition = Vector3.zero
panel.clipOffset = Vector2.zero
panel.baseClipRegion = MyUtl.getUIContent(panel, top, bottom)
end
end
MyUtl.getSizeAdjust = function()
return _sizeAdjust
end
---public 拨号
MyUtl.callCust = function(cust)
2020-07-08 08:01:34 +08:00
if type(cust.jsonStr) == "string" then
cust.jsonStr = json.decode(cust.jsonStr)
2020-07-04 14:41:25 +08:00
end
2020-07-08 08:01:34 +08:00
cust.jsonStr = cust.jsonStr or {}
2020-07-04 14:41:25 +08:00
local phones = ArrayList()
2020-07-09 08:50:24 +08:00
local phonesVal = ArrayList()
2020-07-04 14:41:25 +08:00
local taskId = tostring(cust.taskId)
local fields = DBCust.getFieldsByTask(taskId)
for i, attr in ipairs(fields) do
if attr.attrType == DBCust.FieldType.phone then
2020-07-08 08:01:34 +08:00
local phNo = cust.jsonStr[joinStr(attr.id, "_", attr.attrName)]
2020-07-04 14:41:25 +08:00
if not isNilOrEmpty(phNo) then
2020-07-15 23:35:13 +08:00
phones:Add(joinStr(attr.attrName, ": ", MyUtl.hidePhone(phNo)))
2020-07-09 08:50:24 +08:00
phonesVal:Add(phNo)
2020-07-04 14:41:25 +08:00
end
end
end
if phones.Count > 0 then
2020-07-15 23:35:13 +08:00
phones:Insert(0, joinStr("默认: ", MyUtl.hidePhone(cust.phoneNo)))
2020-07-09 08:50:24 +08:00
phonesVal:Insert(0, cust.phoneNo)
2020-07-04 14:41:25 +08:00
CLUIPopListPanel.show(
phones,
2020-07-09 08:50:24 +08:00
phonesVal,
2020-07-04 14:41:25 +08:00
function(val, selectedItem)
if val then
2020-07-10 22:33:30 +08:00
MyUtl.doCall(cust.custId, val, cust)
2020-07-04 14:41:25 +08:00
end
end
)
else
2020-07-10 22:33:30 +08:00
MyUtl.doCall(cust.custId, cust.phoneNo, cust)
2020-07-04 14:41:25 +08:00
end
end
2020-07-10 22:33:30 +08:00
MyUtl.doCall = function(custId, phoneNo, cust)
2020-07-04 14:41:25 +08:00
showHotWheel("拨号中...")
NetProto.send.bi_call(
custId,
phoneNo,
nil,
function(content)
hideHotWheel()
if content.success then
2020-07-09 09:23:09 +08:00
MyUtl.toastS("拨号成功!")
2020-07-18 21:12:14 +08:00
getPanelAsy("PanelNewFollowSimple", onLoadedPanelTT, cust)
2020-07-04 14:41:25 +08:00
end
end
)
end
2020-07-09 08:50:24 +08:00
MyUtl.toast = function(msg, staySec)
CLToastRoot.toast(msg, CLToastRoot.Type.normal, staySec)
end
MyUtl.toastS = function(msg, staySec)
CLToastRoot.toast(msg, CLToastRoot.Type.success, staySec)
end
MyUtl.toastW = function(msg, staySec)
CLToastRoot.toast(msg, CLToastRoot.Type.warning, staySec)
end
MyUtl.toastE = function(msg, staySec)
CLToastRoot.toast(msg, CLToastRoot.Type.error, staySec)
end
2020-07-11 17:07:30 +08:00
MyUtl.confirm = function(msg, callback, buttonName)
getPanelAsy("PanelConfirm2", onLoadedPanelTT, {msg = msg, callback = callback, buttonName = buttonName})
end
2020-07-15 20:53:37 +08:00
MyUtl.isHidePhone = true
function MyUtl.setIsHidePhone(val)
MyUtl.isHidePhone = (val == 1 and true or false)
end
MyUtl.hidePhone = function(phone)
2020-08-07 22:40:04 +08:00
if not phone then
return
end
2020-07-15 20:53:37 +08:00
if not MyUtl.isHidePhone then
return phone
end
if #phone > 8 then
2020-08-04 21:58:27 +08:00
return joinStr(string.sub(phone, 1, 3), "****", string.sub(phone, 8))
2020-07-15 20:53:37 +08:00
else
2020-08-04 21:58:27 +08:00
return joinStr(string.sub(phone, 1, 3), "****")
2020-07-15 20:53:37 +08:00
end
end
2020-08-07 07:27:09 +08:00
MyUtl.Images = {
[".JPG"] = true,
[".JPEG"] = true,
[".PNG"] = true,
[".PDF"] = true,
[".BMP"] = true,
2020-08-07 22:40:04 +08:00
[".TGA"] = true,
[".GIF"] = true
2020-08-07 07:27:09 +08:00
}
---public 是图片
MyUtl.isImage = function(path)
local extension = Path.GetExtension(path)
return MyUtl.Images[string.upper(extension)] or false
end
2020-08-07 22:40:04 +08:00
---@param oldTexture UnityEngine.Texture2D
MyUtl.CompressImage = function(imgPath, maxSize, quality)
if not File.Exists(imgPath) then
printe("文件不存在==".. imgPath)
return
end
-- int quality = 80;//图片压缩质量1-100
quality = quality or 75
local bytes = File.ReadAllBytes(imgPath)
---@type UnityEngine.Texture2D
local texture = Texture2D(2, 2)
ImageConversion.LoadImage(texture, bytes)
texture = MyFileOpen.ResizeTexture(texture, maxSize, MyFileOpen.ImageFilterMode.Average)
local newBytes = ImageConversion.EncodeToJPG(texture, quality)
return newBytes
end
2020-07-04 14:41:25 +08:00
return MyUtl