Files
tianrunCRM/Assets/trCRM/upgradeRes4Dev/priority/lua/ui/cell/TRCellImage.lua

120 lines
3.3 KiB
Lua
Raw Normal View History

2020-07-18 21:12:14 +08:00
---@class _ParamCellImage
---@field path string
---@field onDelete function
2020-08-01 17:55:18 +08:00
---@field uploadInfor table
2020-07-18 21:12:14 +08:00
-- xx单元
local _cell = {}
---@type Coolape.CLCellLua
local csSelf = nil
local transform = nil
---@type _ParamCellImage
local mData = nil
local uiobjs = {}
2020-08-01 17:55:18 +08:00
local www
2020-07-18 21:12:14 +08:00
-- 初始化,只调用一次
function _cell.init(csObj)
csSelf = csObj
transform = csSelf.transform
---@type UITexture
uiobjs.texture = csSelf:GetComponent("UITexture")
2020-08-01 17:55:18 +08:00
uiobjs.SpriteProgress = getCC(transform, "SpriteProgress", "UISprite")
uiobjs.LabelPersent = getCC(uiobjs.SpriteProgress.transform, "LabelPersent", "UILabel")
uiobjs.Failed = getChild(transform, "Failed")
uiobjs.success = getChild(transform, "success")
2020-07-18 21:12:14 +08:00
end
-- 显示,
-- 注意c#侧不会在调用show时调用refresh
function _cell.show(go, data)
mData = data
local url
if startswith(mData.path, "/") then
url = joinStr("file://", mData.path)
else
url = mData.path
end
if uiobjs.texture.mainTexture and uiobjs.texture.mainTexture.name == mData.path then
else
_cell.release()
DBTextures.getByUrl(url, _cell.onGetTextue, mData.path)
end
2020-08-01 17:55:18 +08:00
SetActive(uiobjs.success.gameObject, false)
_cell.upload()
end
function _cell.upload()
SetActive(uiobjs.Failed.gameObject, false)
www =
DBTextures.upload(
mData.path,
DBOrder.getUploadPath(),
function(content)
www = nil
SetActive(uiobjs.SpriteProgress.gameObject, false)
if content and content.success then
mData.uploadInfor = content.result
SetActive(uiobjs.success.gameObject, true)
else
-- 显示重传按钮
SetActive(uiobjs.Failed.gameObject, true)
local msg = content and content.message or "上传失败"
MyUtl.toastW(msg)
end
end
)
_cell.refreshProgress()
end
function _cell.refreshProgress()
if www == nil then
SetActive(uiobjs.SpriteProgress.gameObject, false)
return
end
SetActive(uiobjs.SpriteProgress.gameObject, true)
local progressVal = www.uploadProgress or 0 -- downloadProgress uploadProgress
uiobjs.LabelPersent.text = PStr.b():a(math.floor(progressVal * 100)):a("%"):e()
uiobjs.SpriteProgress.fillAmount = progressVal
csSelf:invoke4Lua(_cell.refreshProgress, 0.1)
2020-07-18 21:12:14 +08:00
end
function _cell.onGetTextue(content, orgs)
if mData.path ~= orgs then
GameObject.DestroyImmediate(content)
content = nil
return
end
_cell.release()
content.name = orgs
uiobjs.texture.mainTexture = content
end
function _cell.release()
if uiobjs.texture.mainTexture ~= nil then
uiobjs.texture.mainTexture = nil
end
end
-- 取得数据
function _cell.getData()
return mData
end
function _cell.uiEventDelegate(go)
if go.name == "ButtonDel" then
2020-08-01 17:55:18 +08:00
csSelf:cancelInvoke4Lua(_cell.refreshProgress)
DBTextures.cancelUpload(mData.path, DBOrder.getUploadPath())
www = nil
2020-07-18 21:12:14 +08:00
Utl.doCallback(mData.onDelete, mData)
2020-08-01 17:55:18 +08:00
elseif go.name == "ButtonReload" then
_cell.upload()
2020-07-18 21:12:14 +08:00
end
end
--------------------------------------------
return _cell