---@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() DBAttachment.getByUrl(url, _cell.onGetTextue, mData.path) end SetActive(uiobjs.success.gameObject, false) _cell.upload() end function _cell.upload() SetActive(uiobjs.Failed.gameObject, false) www = DBAttachment.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) DBAttachment.cancelUpload(mData.path, DBOrder.getUploadPath()) www = nil Utl.doCallback(mData.onDelete, mData) elseif go.name == "ButtonReload" then _cell.upload() end end -------------------------------------------- return _cell