HtmlUtil.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ------------------------------------
  2. -- 常用Html函数封装
  3. -- font
  4. -- fontAFlag
  5. -- fontAFlagU
  6. -- fontItem 道具信息转字符串
  7. -- fontJYTeamLink 精英战队邀请链接
  8. ------------------------------------
  9. Json = Json or require("common.Json")
  10. local Util = require("common.Util")
  11. local Lang = require("common.Lang")
  12. local Config = require("Config")
  13. local Msg = require("core.Msg")
  14. --local Grid = require("bag.Grid")
  15. --local ItemDefine = require("bag.ItemDefine")
  16. TYPE_SHOW_ITEM = 1 -- 展示道具
  17. TYPE_JOIN_JYTEAM = 2 -- 加入精英战队
  18. TYPE_OPEN_PANEL = 3 -- 打开面板
  19. TYPE_FISH_QIANG = 4 -- 抢鱼
  20. colorTable = {
  21. "#ffffff", --白色
  22. "#1bff2b", --绿色
  23. "#1f9eff", --蓝色
  24. "#ff29f7", --紫色
  25. "#fffe0d", --黄色
  26. "#ff9d1d", --橙色
  27. "#ff1a1a", --红色
  28. }
  29. mapColorTable = {
  30. "#1f9eff", --水
  31. "#f40f0b", --火
  32. "#1bff2b", --草
  33. "#ff9d1d", --光
  34. "#ff29f7" --暗
  35. }
  36. function fontAFlagU(data, content)
  37. return "<a href=\'" .. data .."\'>" .. content .. "</a>"
  38. end
  39. function font(content, color)
  40. if type(color) == "number" then
  41. color = colorTable[color]
  42. else
  43. color = color or colorTable[1]
  44. end
  45. return "<font color='" .. color .. "'>" .. content .. "</font>"
  46. end
  47. function fontItem(grid, index, human)
  48. if not grid or grid.id == 0 then
  49. return ""
  50. end
  51. local msgRet = Msg.gc.GC_BAG_CHANGE
  52. Grid.makeItem(msgRet.itemData, grid)
  53. local itemConfig = ItemDefine.getConfig(grid.id)
  54. local itemColor = itemConfig.Color
  55. local data = TYPE_SHOW_ITEM .."|".. Json.Encode(msgRet.itemData)
  56. local itemName = "【" .. itemConfig.Name .. "】"
  57. local content = font(itemName, itemColor)
  58. return fontAFlagU(data, content)
  59. end
  60. function fontJYTeamLink(content, jyid)
  61. local data = TYPE_JOIN_JYTEAM .. "|" .. jyid .. "|" .. Config.SVR_INDEX
  62. return font(fontAFlagU(data, content), "#1bff2b")
  63. end
  64. function fontFishQiangLink(content, uuid)
  65. local data = TYPE_FISH_QIANG .. "|" .. uuid
  66. return font(fontAFlagU(data, content), "#1bff2b")
  67. end
  68. function fontOpenPanel(content, panelID)
  69. local data = TYPE_OPEN_PANEL .. "|" .. panelID
  70. return fontAFlagU(data, content)
  71. end
  72. function getFormatTime(sec)
  73. if sec < 60 then
  74. return Util.format(Lang.COMMON_STR_TIME1, sec)
  75. end
  76. local min = math.floor(sec / 60)
  77. sec = sec % 60
  78. if min < 60 then
  79. return Util.format(Lang.COMMON_STR_TIME2, min, sec)
  80. end
  81. local hour = math.floor(min / 60)
  82. min = min % 60
  83. return Util.format(Lang.COMMON_STR_TIME3, hour, min, sec)
  84. end
  85. -- 传入一个时间戳 返回xx年x月x日 例如:2019年1月29日
  86. function getDataStr(ts)
  87. local d = os.date("*t",ts)
  88. return Util.format(Lang.COMMON_STR_TIME_YMD, d.year, d.month, d.day)
  89. end
  90. function getDataStrMD(ts)
  91. local d = os.date("*t",ts)
  92. return Util.format(Lang.COMMON_STR_TIME_MD, d.month, d.day)
  93. end