You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
4.1 KiB

  1. -- 分享界面
  2. local ShareZhanJiUrlView = class("ShareZhanJiUrlView", cc.UIView)
  3. --按钮对应编号
  4. -- 1 : 微信
  5. -- 2 : 复制
  6. -- 3 : 茶馆
  7. --[[
  8. shareData tableData
  9. @parm:
  10. scene:分享场景
  11. contentType
  12. title
  13. description
  14. image
  15. imageWidth
  16. thumbWidth
  17. menuIdxs
  18. url
  19. copyData
  20. ]]
  21. -- menuIdxs = {1,2,3}
  22. -- shareData:分享内容
  23. -- copyData :复制内容
  24. -- shareCallbakc : 点击按钮之后的回调
  25. -- dataForUrl : 分享战绩链接需要的内容
  26. function ShareZhanJiUrlView:ctor(url,zhanjiInfo,menuIdxs)
  27. ShareZhanJiUrlView.super.ctor(self)
  28. --需要显示的按钮
  29. self.menuIdxs = menuIdxs or {1,4,5,8}
  30. -- self.shareInfo =
  31. -- {
  32. -- contentType = "url",
  33. -- scene = "talk",
  34. -- url = url,
  35. -- title = gameName.."战绩",
  36. -- description = content,
  37. -- image = imagePath,
  38. -- imageWidth = 100,
  39. -- };
  40. local gameID = tonumber(zhanjiInfo.gameid)
  41. local scoreList = zhanjiInfo.tscore
  42. local roomId = zhanjiInfo.roomid
  43. local ext = zhanjiInfo.gext or {}
  44. local gameRule = ext.gamerule
  45. local scoreStr = ""
  46. local gameConfig = getSubGameConfig(gameID) or {}
  47. for k,score in pairsByKeys(scoreList) do
  48. --名字
  49. local playerInfo = app.playerInfoManager:getPlayerInfo(k)
  50. if gameConfig.isUseDivision10 then
  51. score = score/10
  52. end
  53. if playerInfo then
  54. local len = string.len(playerInfo.name)
  55. if len == 0 then
  56. playerInfo.name = "未知昵称"
  57. end
  58. scoreStr = string.format("%s%s(%s) ", scoreStr, playerInfo.name,score>=0 and "+".. score or score)
  59. -- if k~=#scoreList then
  60. -- scoreStr = scoreStr .. ","
  61. -- end
  62. end
  63. end
  64. scoreStr = scoreStr.."\n<仅供娱乐,严禁赌博>"
  65. local gameName = getSubGameRuleName(gameID, gameRule) or "悠闲麻将"
  66. local shareUrl = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
  67. url,
  68. app.user.loginInfo.uid,
  69. gameID,
  70. getAppId(),
  71. roomId,
  72. zhanjiInfo.endtime)
  73. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  74. self.shareInfo =
  75. {
  76. contentType = "url",
  77. scene = "talk",
  78. url = shareUrl,
  79. title = gameName.."战绩",
  80. description = scoreStr,
  81. image = imagePath,
  82. imageWidth = 100,
  83. };
  84. dump(self.shareInfo)
  85. end
  86. function ShareZhanJiUrlView:onEnter()
  87. ShareZhanJiUrlView.super.onEnter(self)
  88. self.ui = loadUI("res/ui/ui_dating/ui_share.ui")
  89. self:addChild(self.ui)
  90. self.ui.Items.Layout_touch:registerClick(handler(self, self.onClickClose))
  91. --微信分享
  92. self.ui.Items.Button_wechat:registerClick(handler(self, self.wechatShare))
  93. self:initData();
  94. end
  95. --
  96. function ShareZhanJiUrlView:initData()
  97. --是否开启微信分享屏蔽
  98. local clubInfo = nil
  99. if self.clubID and self.clubID ~= 0 then
  100. clubInfo = app.club_php.clubList[tonumber(self.clubID)];
  101. elseif app.club_php.clubID and app.club_php.clubID ~= 0 then
  102. clubInfo = app.club_php.clubList[tonumber(app.club_php.clubID)];
  103. -- if not clubInfo then
  104. -- --未找到茶馆列表数据时,请求茶馆列表(可能是断线重连)
  105. -- app.club_php:requestOneClubInfo(app.club_php.clubID);
  106. -- end
  107. end
  108. -- 将需要显示的按钮索引标为 true
  109. --隐私数据
  110. local isForbidShare = false
  111. if clubInfo then
  112. self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
  113. local defaultValue = self.cliext and self.cliext.is_wxshare or clubInfo.isWxshare or 0
  114. isForbidShare = defaultValue == 1
  115. end
  116. local tt = {}
  117. for k,idx in pairs(self.menuIdxs) do
  118. if idx == 1 and isForbidShare then
  119. --微信分享已屏蔽
  120. tt[idx] = false
  121. else
  122. tt[idx] = true
  123. end
  124. end
  125. -- 隐藏不相关的按钮
  126. for i = 1,8 do
  127. local name = string.format("Layout_Btn_%d", i)
  128. local node = self.ui.Items[name]
  129. if node then
  130. -- 标记为true的显示
  131. -- 否则不显示
  132. if tt[i] then
  133. node:setVisible(true)
  134. else
  135. node:setVisible(false)
  136. end
  137. end
  138. end
  139. -- 重新布局
  140. self.ui.Items.Layout_btn:requestDoLayout()
  141. self.ui.Items.Layout_btn:doLayout()
  142. end
  143. --微信分享
  144. function ShareZhanJiUrlView:wechatShare()
  145. app.plugin:shareGame(self.shareInfo, self.shareCallbakc);
  146. self:onClickClose();
  147. end
  148. -- 关闭响应函数
  149. function ShareZhanJiUrlView:onClickClose()
  150. playBtnEffect()
  151. self:removeFromParent()
  152. end
  153. return ShareZhanJiUrlView