Files
tianrunCRM/Assets/trCRM/upgradeRes4Dev/priority/lua/ui/cell/TRCellImage.lua
2020-08-01 17:55:18 +08:00

120 lines
3.3 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---@class _ParamCellImage
---@field path string
---@field onDelete function
---@field uploadInfor table
-- xx单元
local _cell = {}
---@type Coolape.CLCellLua
local csSelf = nil
local transform = nil
---@type _ParamCellImage
local mData = nil
local uiobjs = {}
local www
-- 初始化,只调用一次
function _cell.init(csObj)
csSelf = csObj
transform = csSelf.transform
---@type UITexture
uiobjs.texture = csSelf:GetComponent("UITexture")
uiobjs.SpriteProgress = getCC(transform, "SpriteProgress", "UISprite")
uiobjs.LabelPersent = getCC(uiobjs.SpriteProgress.transform, "LabelPersent", "UILabel")
uiobjs.Failed = getChild(transform, "Failed")
uiobjs.success = getChild(transform, "success")
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
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)
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
csSelf:cancelInvoke4Lua(_cell.refreshProgress)
DBTextures.cancelUpload(mData.path, DBOrder.getUploadPath())
www = nil
Utl.doCallback(mData.onDelete, mData)
elseif go.name == "ButtonReload" then
_cell.upload()
end
end
--------------------------------------------
return _cell