mm
This commit is contained in:
@@ -3,6 +3,9 @@ local db = {}
|
||||
|
||||
local dbUploadStatus = {}
|
||||
local isUploading = {}
|
||||
local isDownoading = {}
|
||||
local downloadCallback = {}
|
||||
local downloadDir = Utl.chgToSDCard(Path.Combine(Application.persistentDataPath, CLPathCfg.self.basePath, "download"))
|
||||
|
||||
function DBTextures.init()
|
||||
InvokeEx.cancelInvoke(DBTextures.releaseTimeout)
|
||||
@@ -99,4 +102,66 @@ function DBTextures.cancelUpload(path, uploadPath)
|
||||
end
|
||||
end
|
||||
|
||||
function DBTextures.hadDownloaded(name)
|
||||
local localPath = Path.Combine(downloadDir, name)
|
||||
if File.Exists(localPath) then
|
||||
return true, localPath
|
||||
end
|
||||
return false, localPath
|
||||
end
|
||||
|
||||
function DBTextures.download(name, url, callback)
|
||||
downloadCallback[name] = callback
|
||||
if isDownoading[name] then
|
||||
return isDownoading[name]
|
||||
end
|
||||
local localPath = Path.Combine(downloadDir, name)
|
||||
local _url = url
|
||||
if File.Exists(localPath) then
|
||||
_url = Path.Combine("file://", localPath)
|
||||
end
|
||||
local assetType
|
||||
if MyUtl.isImage(name) then
|
||||
assetType = CLAssetType.texture
|
||||
else
|
||||
assetType = CLAssetType.bytes
|
||||
end
|
||||
|
||||
local www =
|
||||
WWWEx.get(
|
||||
_url,
|
||||
nil,
|
||||
CLAssetType.texture,
|
||||
function(content, orgs)
|
||||
isDownoading[name] = nil
|
||||
if content then
|
||||
local bytes
|
||||
if assetType == CLAssetType.texture then
|
||||
bytes = content:GetRawTextureData()
|
||||
else
|
||||
bytes = content
|
||||
end
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(localPath))
|
||||
File.WriteAllBytes(localPath, bytes)
|
||||
Utl.doCallback(downloadCallback[name], content, localPath)
|
||||
downloadCallback[name] = nil
|
||||
else
|
||||
MyUtl.toastW("下载附件为空")
|
||||
Utl.doCallback(downloadCallback[name], content, nil)
|
||||
downloadCallback[name] = nil
|
||||
end
|
||||
end,
|
||||
function()
|
||||
isDownoading[name] = nil
|
||||
MyUtl.toastW("下载附件失败")
|
||||
Utl.doCallback(downloadCallback[name], nil, nil)
|
||||
downloadCallback[name] = nil
|
||||
end,
|
||||
nil,
|
||||
true,
|
||||
2
|
||||
)
|
||||
isDownoading[name] = www
|
||||
end
|
||||
|
||||
return DBTextures
|
||||
|
||||
@@ -129,4 +129,18 @@ MyUtl.hidePhone = function(phone)
|
||||
end
|
||||
end
|
||||
|
||||
MyUtl.Images = {
|
||||
[".JPG"] = true,
|
||||
[".JPEG"] = true,
|
||||
[".PNG"] = true,
|
||||
[".PDF"] = true,
|
||||
[".BMP"] = true,
|
||||
[".GIF"] = true,
|
||||
}
|
||||
|
||||
---public 是图片
|
||||
MyUtl.isImage = function(path)
|
||||
local extension = Path.GetExtension(path)
|
||||
return MyUtl.Images[string.upper(extension)] or false
|
||||
end
|
||||
return MyUtl
|
||||
|
||||
@@ -5,6 +5,8 @@ local csSelf = nil
|
||||
local transform = nil
|
||||
local mData = nil
|
||||
local uiobjs = {}
|
||||
local isDownLoading = false
|
||||
local www
|
||||
|
||||
-- 初始化,只调用一次
|
||||
function _cell.init(csObj)
|
||||
@@ -13,14 +15,29 @@ function _cell.init(csObj)
|
||||
uiobjs.Label = getCC(transform, "Label", "UILabel")
|
||||
uiobjs.ButtonDel = getChild(transform, "ButtonDel").gameObject
|
||||
uiobjs.SpriteIcon = getCC(transform, "SpriteIcon", "UISprite")
|
||||
|
||||
uiobjs.ButtonDownload = getChild(transform, "ButtonDownload").gameObject
|
||||
uiobjs.DownloadProgress = getChild(transform, "DownloadProgress")
|
||||
uiobjs.DownloadProgressLb = getCC(uiobjs.DownloadProgress, "Label", "UILabel")
|
||||
end
|
||||
|
||||
-- 显示,
|
||||
-- 注意,c#侧不会在调用show时,调用refresh
|
||||
function _cell.show(go, data)
|
||||
mData = data
|
||||
SetActive(uiobjs.ButtonDel, false)
|
||||
uiobjs.Label.text = mData.name
|
||||
if MyUtl.isImage(mData.name) then
|
||||
--//TODO:
|
||||
else
|
||||
end
|
||||
|
||||
--//TODO:权限判断,如果有权限的可以考虑直接显示图片
|
||||
if DBTextures.hadDownloaded(mData.name) then
|
||||
SetActive(uiobjs.ButtonDownload, false)
|
||||
else
|
||||
SetActive(uiobjs.ButtonDownload, true)
|
||||
end
|
||||
end
|
||||
|
||||
-- 取得数据
|
||||
@@ -28,5 +45,49 @@ function _cell.getData()
|
||||
return mData
|
||||
end
|
||||
|
||||
function _cell.download()
|
||||
if isDownLoading then
|
||||
return
|
||||
end
|
||||
|
||||
isDownLoading = true
|
||||
SetActive(uiobjs.ButtonDownload, false)
|
||||
www =
|
||||
DBTextures.download(
|
||||
mData.name,
|
||||
mData.url,
|
||||
function(content, localPath)
|
||||
isDownLoading = false
|
||||
www = nil
|
||||
if content and localPath then
|
||||
-- 附件下载完成
|
||||
MyUtl.toastS(joinStr("附件已保存本地:" .. localPath))
|
||||
else
|
||||
SetActive(uiobjs.ButtonDownload, true)
|
||||
end
|
||||
end
|
||||
)
|
||||
_cell.refreshProgress()
|
||||
end
|
||||
|
||||
function _cell.refreshProgress()
|
||||
if www == nil then
|
||||
SetActive(uiobjs.DownloadProgress.gameObject, false)
|
||||
return
|
||||
else
|
||||
SetActive(uiobjs.DownloadProgress.gameObject, true)
|
||||
local progressVal = www.downloadProgress or 0 -- downloadProgress uploadProgress
|
||||
uiobjs.LabelPersent.text = joinStr(math.floor(progressVal * 100), "%")
|
||||
end
|
||||
|
||||
csSelf:invoke4Lua(_cell.refreshProgress, 0.1)
|
||||
end
|
||||
|
||||
function _cell.uiEventDelegate(go)
|
||||
if go.name == "ButtonDownload" then
|
||||
_cell.download()
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------
|
||||
return _cell
|
||||
|
||||
@@ -105,10 +105,10 @@ function _cell.onFinisInitFields()
|
||||
uiobjs.Table.repositionNow = true
|
||||
hideHotWheel()
|
||||
|
||||
isLoading = false
|
||||
csSelf:invoke4Lua(
|
||||
function()
|
||||
Utl.doCallback(mData.onFinish, csSelf.gameObject)
|
||||
isLoading = false
|
||||
-- 再次处理
|
||||
_cell.refresh()
|
||||
end,
|
||||
@@ -121,6 +121,8 @@ function _cell.release()
|
||||
SetActive(v.gameObject, false)
|
||||
CLUIOtherObjPool.returnObj(v.gameObject)
|
||||
end
|
||||
|
||||
isLoading = false
|
||||
fieldsObjs = {}
|
||||
count = 0
|
||||
end
|
||||
@@ -144,7 +146,7 @@ end
|
||||
|
||||
function _cell.OnDisable()
|
||||
if #(fieldsObjs) > 0 then
|
||||
printe("动态加载的字段没有释放" .. csSelf.name)
|
||||
printw("动态加载的字段没有释放" .. csSelf.name)
|
||||
end
|
||||
end
|
||||
--------------------------------------------
|
||||
|
||||
@@ -294,6 +294,21 @@ function TRPOrderDetail:initAttachmentCell(cell, data)
|
||||
end
|
||||
|
||||
function TRPOrderDetail:onClickAttachment(cell, data)
|
||||
local had, path = DBTextures.hadDownloaded(data.name)
|
||||
if had then
|
||||
CLUIUtl.showConfirm(
|
||||
joinStr("附件已保存本地:", path),
|
||||
false,
|
||||
"打开",
|
||||
function()
|
||||
Application.OpenURL(joinStr("file://", path))
|
||||
end,
|
||||
"取消",
|
||||
nil
|
||||
)
|
||||
else
|
||||
MyUtl.toastW("附件未下载完成,暂时无法查看")
|
||||
end
|
||||
end
|
||||
|
||||
function TRPOrderDetail:showRecords()
|
||||
@@ -493,7 +508,6 @@ function TRPOrderDetail:addAttachment(go)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function TRPOrderDetail:onGetImage(path)
|
||||
if isNilOrEmpty(path) then
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user