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.

449 lines
12 KiB

  1. -- 分享界面
  2. local ShareView = class("ShareView", cc.UIView)
  3. --按钮对应编号
  4. -- 1 : 微信
  5. -- 2 : 复制
  6. -- 3 : 茶馆
  7. -- 7 : 网页战绩
  8. --[[
  9. shareData tableData
  10. @parm:
  11. scene:分享场景
  12. contentType
  13. title
  14. description
  15. image
  16. imageWidth
  17. thumbWidth
  18. menuIdxs
  19. url
  20. copyData
  21. ]]
  22. -- menuIdxs = {1,2,3}
  23. -- shareData:分享内容
  24. -- copyData :复制内容
  25. -- shareCallbakc : 点击按钮之后的回调
  26. -- dataForUrl : 分享战绩链接需要的内容
  27. --,isCoinGame:是否是金币场
  28. function ShareView:ctor(shareData,shareCallbakc, dataForUrl,isCoinGame)
  29. ShareView.super.ctor(self)
  30. --房间号
  31. if app.room and app.room.roomInfo and app.room.roomInfo.nShowTableId then
  32. self.roomID = app.room.roomInfo.nShowTableId
  33. end
  34. --游戏规则
  35. self.gameMode = shareData.gameMode or ""
  36. --分享数据
  37. shareData.scene = shareData.scene or "talk"
  38. shareData.contentType = shareData.contentType or "url"
  39. shareData.title = shareData.title or ""
  40. local srcDescription = shareData.description
  41. shareData.description = "<仅供娱乐,严禁赌博>\n"..(shareData.description or "")
  42. shareData.image = shareData.image or cc.FileUtils:getInstance():getWritablePath().."icon.png"
  43. shareData.imageWidth = shareData.imageWidth or 100
  44. --略缩图大小
  45. shareData.thumbWidth = shareData.thumbWidth or 100
  46. --分享选项
  47. shareData.menuIdxs = shareData.menuIdxs or {1,2,4,5,6}
  48. local url = app.config.Setting.appDownloadUrl
  49. local paramGameID
  50. if shareData and shareData.copyData and shareData.copyData.gameId then
  51. paramGameID = shareData.copyData.gameId
  52. end
  53. local gameID = paramGameID or app.gameId
  54. local playerID = app.user.loginInfo.uid
  55. local prefix = "&"
  56. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  57. if app.room and app.room.roomInfo and app.room.roomInfo.nShowTableId then
  58. url = string.format(url .. prefix .. "uid=%d&tableId=%d&clubid=%d", playerID, app.room.roomInfo.nShowTableId,app.club_php.clubID)
  59. else
  60. url = string.format(url .. prefix .. "uid=%d&clubid=%d", playerID, app.club_php.clubID)
  61. end
  62. else
  63. if app.room and app.room.roomInfo and app.room.roomInfo.nShowTableId then
  64. url = string.format(url .. prefix .. "uid=%d&tableId=%d", playerID, app.room.roomInfo.nShowTableId)
  65. else
  66. url = string.format(url .. prefix .. "uid=%d", playerID)
  67. end
  68. end
  69. shareData.url = shareData.url or url
  70. --复制数据
  71. local copyData=""
  72. if shareData.copyData then
  73. dump(shareData.copyData,"-ShareView-")
  74. --如果是table 2种情况一个是总结算(type=1) 一个是房间内邀请(type=2)
  75. if type(shareData.copyData)=="table" then
  76. if shareData.copyData.type==1 then
  77. --总结算格式
  78. -- copyData={
  79. -- type=1,
  80. -- gameId=1,
  81. -- tableId=123456,
  82. -- userInofs={
  83. -- {nickname="xxx",totalScore=0},
  84. -- {nickname="xxx",totalScore=0},
  85. -- }
  86. -- }
  87. --游戏名
  88. local curGameID = shareData.copyData.gameId or app.gameId
  89. --local curGameRule = shareData.copyData.gameRule
  90. local gameName = shareData.gameName or getSubGameName(curGameID) or "悠闲麻将"
  91. --[[local gameConfig = getSubGameConfig(curGameID)
  92. if gameConfig and gameConfig.bSingleGame then
  93. gameName = getSubGameRuleName(curGameID,curGameRule)
  94. end--]]
  95. --房间号
  96. local tableId = shareData.copyData.tableId or app.room.roomInfo.nShowTableId
  97. --时间
  98. local endTime = os.date("%Y-%m-%d %X")
  99. --用户数据信息
  100. local scoreStr=""
  101. if shareData.copyData.userInfos then
  102. --金币场机器人userid太大暴露,屏蔽
  103. if isCoinGame then
  104. for k,user in pairs(shareData.copyData.userInfos) do
  105. scoreStr = string.format("%s[%s] %s分\n", scoreStr, user.nickname,user.totalScore>=0 and "+".. user.totalScore or user.totalScore)
  106. end
  107. else
  108. for k,user in pairs(shareData.copyData.userInfos) do
  109. scoreStr = string.format("%s[%s] %s分\n", scoreStr, getShortName2(user.nickname), user.totalScore>=0 and "+".. user.totalScore or user.totalScore)
  110. end
  111. end
  112. end
  113. local endStr = "竞技成绩仅供娱乐,禁止赌博!"
  114. if isCoinGame then --金币场没有房间号
  115. copyData = string.format("[%s]\n结束时间:%s\n成绩:\n%s\n%s",
  116. gameName,
  117. endTime,
  118. scoreStr,
  119. endStr)
  120. else
  121. copyData = string.format("[%s]\n房间号:%s\n结束时间:%s\n成绩:\n%s\n%s",
  122. gameName,
  123. tableId,
  124. endTime,
  125. scoreStr,
  126. endStr)
  127. end
  128. elseif shareData.copyData.type==2 then
  129. --邀请好友格式
  130. -- copyData={
  131. -- type=2,
  132. -- }
  133. local clubData = ""
  134. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  135. local clubName = ""
  136. local clubList = app.club_php.clubList
  137. if clubList and clubList[tonumber(app.club_php.clubID)] then
  138. clubName = clubList[tonumber(app.club_php.clubID)].clubName;
  139. clubData = string.format("%s:%s \n",(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME), clubName)
  140. end
  141. end
  142. local tishi = "复制信息打开游戏将自动入座\n<仅供娱乐,严禁赌博>"
  143. copyData = string.format("%s%s\n%s\n%s",clubData,
  144. shareData.title,
  145. srcDescription,
  146. tishi)
  147. end
  148. else
  149. copyData = shareData.copyData
  150. end
  151. end
  152. --保存
  153. self.gameID = gameID
  154. --防封群分享标志
  155. self.FFQFlag = shareData.FFQFlag or false
  156. --茶馆id,不在茶馆,则没有此字段
  157. self.clubID = shareData.ClubID
  158. --需要显示的按钮
  159. self.menuIdxs = self:getMenuIdxs(shareData)
  160. --分享内容
  161. self.shareInfo = shareData;
  162. --复制内容
  163. self.copyData = copyData
  164. --回调函数
  165. self.shareCallbakc = shareCallbakc
  166. -- 分享战绩链接需要的内容
  167. self.isShareZhanjiUrl = shareData.isShareZhanjiUrl
  168. self.dataForUrl = dataForUrl or {}
  169. self.zhanjiUrl = app.serverConfigs.clientConfig.webgamb or RomSetting.ZhanJiUrl
  170. end
  171. function ShareView:onEnter()
  172. ShareView.super.onEnter(self)
  173. self.ui = loadUI("res/ui/ui_dating/ui_share.ui")
  174. self:addChild(self.ui)
  175. self.ui.Items.Layout_touch:registerClick(handler(self, self.onClickClose))
  176. -- 微信分享
  177. self:initWechat();
  178. -- 复制
  179. self:initCopy();
  180. -- 茶馆邀请
  181. self.ui.Items.Button_club_invite:registerClick(handler(self, self.onClickClubFriends))
  182. -- 战绩网页分享
  183. self:initShareZhanJiUrl();
  184. self:initData();
  185. end
  186. function ShareView:getSupportType()
  187. return {
  188. WeiXin = {isShowed = true},
  189. }
  190. end
  191. --- ShareView:getMenuIdxs 初始化要显示的分享方式
  192. function ShareView:getMenuIdxs(shareData)
  193. local menuIdxs = {}
  194. local supportType = self:getSupportType()
  195. for k, v in pairs(supportType or {}) do
  196. logD("ShareView:getMenuIdxs", k, v.isShowed)
  197. if v.isShowed then
  198. if k == "WeiXin" then
  199. table.insert(menuIdxs, 1);
  200. end
  201. end
  202. end
  203. if shareData.copyData and shareData.copyData ~= "" then
  204. table.insert(menuIdxs, 2);
  205. end
  206. if shareData.isShareZhanjiUrl and supportType.WebZhanJi.isShowed then
  207. table.insert(menuIdxs, 7);
  208. end
  209. if shareData.isNeedClubShare then
  210. -- 是否需要亲友圈分享
  211. table.insert(menuIdxs, 3);
  212. end
  213. table.sort(menuIdxs, function (a, b)
  214. return a < b;
  215. end)
  216. return menuIdxs
  217. end
  218. --- ShareView:initWechat 微信分享
  219. function ShareView:initWechat()
  220. self.ui.Items.Button_wechat:registerClick(handler(self, self.wechatShare))
  221. end
  222. --- ShareView:initCopy 复制分享
  223. function ShareView:initCopy()
  224. self.ui.Items.Button_copy:registerClick(handler(self, self.onClickCopy))
  225. end
  226. --
  227. function ShareView:initData(isRequest)
  228. --是否开启微信分享屏蔽
  229. local isForbidShare = false
  230. local clubInfo = nil
  231. if self.clubID and self.clubID ~= 0 then
  232. clubInfo = app.club_php.clubList[tonumber(self.clubID)];
  233. elseif app.club_php.clubID and app.club_php.clubID ~= 0 then
  234. clubInfo = app.club_php.clubList[tonumber(app.club_php.clubID)];
  235. if not clubInfo and not isRequest then
  236. --未找到茶馆列表数据时,请求茶馆列表(可能是断线重连)
  237. if IS_USER_NEW_CLUB then
  238. app.waitDialogManager:showWaitNetworkDialog("获取数据中...")
  239. app.club_php:requestClubList(function()
  240. app.waitDialogManager:closeWaitNetworkDialog()
  241. self:initData(true)
  242. end)
  243. else
  244. app.club_php:requestOneClubInfo(app.club_php.clubID);
  245. end
  246. end
  247. end
  248. if clubInfo then
  249. --隐私数据
  250. self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
  251. local defaultValue = self.cliext and self.cliext.is_wxshare or clubInfo.isWxshare or 0
  252. isForbidShare = defaultValue == 1
  253. end
  254. -- 将需要显示的按钮索引标为 true
  255. local tt = {}
  256. for k,idx in pairs(self.menuIdxs) do
  257. if k == 1 and isForbidShare and (not self.FFQFlag) then--微信分享屏蔽且不是防封群分享就不显示微信按钮
  258. --微信分享已屏蔽
  259. tt[idx] = false
  260. else
  261. tt[idx] = true
  262. end
  263. end
  264. -- 隐藏不相关的按钮
  265. local index = 0
  266. for i = 1,8 do
  267. local name = string.format("Layout_Btn_%d", i)
  268. local node = self.ui.Items[name]
  269. if node and not tolua.isnull(node) then
  270. -- 标记为true的显示
  271. -- 否则不显示
  272. if tt[i] then
  273. node:setVisible(true)
  274. index = index + 1
  275. else
  276. node:setVisible(false)
  277. end
  278. end
  279. end
  280. if index == 0 then
  281. showTooltip("已关闭微信分享功能,请联系管理员打开!")
  282. end
  283. -- 重新布局
  284. self.ui.Items.Layout_btn:requestDoLayout()
  285. self.ui.Items.Layout_btn:doLayout()
  286. end
  287. function ShareView:initShareZhanJiUrl()
  288. local data = self:getSupportType()
  289. if not data.WebZhanJi.isShowed and not self.isShareZhanjiUrl then --self.isShareZhanjiUrl
  290. if self.ui.Items.Layout_Btn_7 then
  291. self.ui.Items.Layout_Btn_7:setVisible(false);
  292. end
  293. else
  294. app.serverConfigs:requestClientConfig(function()
  295. self.zhanjiUrl = app.serverConfigs.clientConfig.webgamb or RomSetting.ZhanJiUrl
  296. end)
  297. end
  298. self.ui.Items.Button_url:registerClick(handler(self, self.onClickShareUrl))
  299. end
  300. --微信分享
  301. function ShareView:wechatShare()
  302. app.plugin:shareGame(self.shareInfo, self.shareCallbakc);
  303. self:onClickClose();
  304. end
  305. -- 关闭响应函数
  306. function ShareView:onClickClose()
  307. playBtnEffect()
  308. self:removeFromParent()
  309. end
  310. --复制
  311. function ShareView:onClickCopy()
  312. if self.copyData and type(self.copyData) == "string" then
  313. log("ShareView:onClickCopy() copyData =", self.copyData)
  314. copyStringToClipboard(self.copyData)
  315. else
  316. copyStringToClipboard("")
  317. end
  318. app.plugin:gotoWeiXin();
  319. self:onClickClose();
  320. end
  321. --茶馆邀请
  322. function ShareView:onClickClubFriends()
  323. playBtnEffect();
  324. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  325. local view = import("luaScript.Views.Club.ClubInvite"):new(self.roomID, self.gameMode)
  326. view:setAnchorPoint(cc.p(0.5, 0.5))
  327. app:showWaitDialog(view)
  328. end
  329. self:onClickClose();
  330. end
  331. function ShareView:onClickShareUrl()
  332. if not self.zhanjiUrl then
  333. showTooltip("链接无效,请使用其他分享方式");
  334. return
  335. end
  336. local dataForUrl = {
  337. app = getAppId(),
  338. uid = self.dataForUrl.uid or app.user.loginInfo.uid,
  339. gameid = self.dataForUrl.gameid or self.gameID,
  340. roomid = self.dataForUrl.roomid or app.room.roomInfo.nShowTableId,
  341. endtime = self.dataForUrl.endtime or os.time(),
  342. }
  343. local url = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
  344. self.zhanjiUrl,
  345. dataForUrl.uid,
  346. dataForUrl.gameid,
  347. dataForUrl.app,
  348. dataForUrl.roomid,
  349. dataForUrl.endtime);
  350. local content = nil;
  351. if self.shareInfo and self.shareInfo.copyData and self.shareInfo.copyData.userInfos then
  352. for k,v in pairs(self.shareInfo.copyData.userInfos) do
  353. local userInfo = ""
  354. if v.totalScore > 0 then
  355. userInfo = string.format("%s(+%s)", getShortName2(v.nickname), v.totalScore)
  356. else
  357. userInfo = string.format("%s(%s)", getShortName2(v.nickname), v.totalScore)
  358. end
  359. if content then
  360. content = content .. "," .. userInfo
  361. else
  362. content = userInfo
  363. end
  364. end
  365. end
  366. content = "<仅供娱乐,严禁赌博>\n"..(content or "")
  367. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  368. local gameName = self.shareInfo.gameName or getSubGameName(self.gameID) or "悠闲麻将"
  369. local shareInfo =
  370. {
  371. contentType = "url",
  372. scene = "talk",
  373. url = url,
  374. title = gameName.."战绩",
  375. description = content,
  376. image = imagePath,
  377. imageWidth = 100,
  378. };
  379. dump(shareInfo)
  380. app.plugin:shareGame(shareInfo, self.shareCallbakc);
  381. end
  382. return ShareView