|
- -- 分享界面
- local ShareZhanJiUrlView = class("ShareZhanJiUrlView", cc.UIView)
-
- --按钮对应编号
- -- 1 : 微信
- -- 2 : 复制
- -- 3 : 茶馆
-
- --[[
- shareData tableData
- @parm:
- scene:分享场景
- contentType
- title
- description
- image
- imageWidth
- thumbWidth
- menuIdxs
- url
- copyData
- ]]
-
- -- menuIdxs = {1,2,3}
- -- shareData:分享内容
- -- copyData :复制内容
- -- shareCallbakc : 点击按钮之后的回调
- -- dataForUrl : 分享战绩链接需要的内容
- function ShareZhanJiUrlView:ctor(url,zhanjiInfo,menuIdxs)
- ShareZhanJiUrlView.super.ctor(self)
-
-
- --需要显示的按钮
- self.menuIdxs = menuIdxs or {1,4,5,8}
-
- -- self.shareInfo =
- -- {
- -- contentType = "url",
- -- scene = "talk",
- -- url = url,
- -- title = gameName.."战绩",
- -- description = content,
- -- image = imagePath,
- -- imageWidth = 100,
- -- };
-
- local gameID = tonumber(zhanjiInfo.gameid)
- local scoreList = zhanjiInfo.tscore
- local roomId = zhanjiInfo.roomid
- local ext = zhanjiInfo.gext or {}
- local gameRule = ext.gamerule
- local scoreStr = ""
- local gameConfig = getSubGameConfig(gameID) or {}
- for k,score in pairsByKeys(scoreList) do
- --名字
- local playerInfo = app.playerInfoManager:getPlayerInfo(k)
- if gameConfig.isUseDivision10 then
- score = score/10
- end
- if playerInfo then
- local len = string.len(playerInfo.name)
- if len == 0 then
- playerInfo.name = "未知昵称"
- end
- scoreStr = string.format("%s%s(%s) ", scoreStr, playerInfo.name,score>=0 and "+".. score or score)
- -- if k~=#scoreList then
- -- scoreStr = scoreStr .. ","
- -- end
- end
- end
- scoreStr = scoreStr.."\n<仅供娱乐,严禁赌博>"
-
- local gameName = getSubGameRuleName(gameID, gameRule) or "悠闲麻将"
-
- local shareUrl = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
- url,
- app.user.loginInfo.uid,
- gameID,
- getAppId(),
- roomId,
- zhanjiInfo.endtime)
-
- local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
-
- self.shareInfo =
- {
- contentType = "url",
- scene = "talk",
- url = shareUrl,
- title = gameName.."战绩",
- description = scoreStr,
- image = imagePath,
- imageWidth = 100,
- };
- dump(self.shareInfo)
- end
-
- function ShareZhanJiUrlView:onEnter()
- ShareZhanJiUrlView.super.onEnter(self)
-
- self.ui = loadUI("res/ui/ui_dating/ui_share.ui")
- self:addChild(self.ui)
-
- self.ui.Items.Layout_touch:registerClick(handler(self, self.onClickClose))
-
- --微信分享
- self.ui.Items.Button_wechat:registerClick(handler(self, self.wechatShare))
-
- self:initData();
- end
-
- --
- function ShareZhanJiUrlView:initData()
- --是否开启微信分享屏蔽
- local clubInfo = nil
- if self.clubID and self.clubID ~= 0 then
- clubInfo = app.club_php.clubList[tonumber(self.clubID)];
- elseif app.club_php.clubID and app.club_php.clubID ~= 0 then
- clubInfo = app.club_php.clubList[tonumber(app.club_php.clubID)];
- -- if not clubInfo then
- -- --未找到茶馆列表数据时,请求茶馆列表(可能是断线重连)
- -- app.club_php:requestOneClubInfo(app.club_php.clubID);
- -- end
- end
-
- -- 将需要显示的按钮索引标为 true
- --隐私数据
- local isForbidShare = false
- if clubInfo then
- self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
- local defaultValue = self.cliext and self.cliext.is_wxshare or clubInfo.isWxshare or 0
- isForbidShare = defaultValue == 1
- end
-
- local tt = {}
- for k,idx in pairs(self.menuIdxs) do
- if idx == 1 and isForbidShare then
- --微信分享已屏蔽
- tt[idx] = false
- else
- tt[idx] = true
- end
- end
-
- -- 隐藏不相关的按钮
- for i = 1,8 do
- local name = string.format("Layout_Btn_%d", i)
- local node = self.ui.Items[name]
- if node then
- -- 标记为true的显示
- -- 否则不显示
- if tt[i] then
- node:setVisible(true)
- else
- node:setVisible(false)
- end
- end
- end
-
- -- 重新布局
- self.ui.Items.Layout_btn:requestDoLayout()
- self.ui.Items.Layout_btn:doLayout()
- end
-
-
- --微信分享
- function ShareZhanJiUrlView:wechatShare()
- app.plugin:shareGame(self.shareInfo, self.shareCallbakc);
- self:onClickClose();
- end
-
-
- -- 关闭响应函数
- function ShareZhanJiUrlView:onClickClose()
- playBtnEffect()
- self:removeFromParent()
- end
-
- return ShareZhanJiUrlView
|