|
- -- 分享界面
- local ShareView = class("ShareView", cc.UIView)
-
- --按钮对应编号
- -- 1 : 微信
- -- 2 : 复制
- -- 3 : 茶馆
-
- -- 7 : 网页战绩
-
- --[[
- shareData tableData
- @parm:
- scene:分享场景
- contentType
- title
- description
- image
- imageWidth
- thumbWidth
- menuIdxs
- url
- copyData
- ]]
-
- -- menuIdxs = {1,2,3}
- -- shareData:分享内容
- -- copyData :复制内容
- -- shareCallbakc : 点击按钮之后的回调
- -- dataForUrl : 分享战绩链接需要的内容
- --,isCoinGame:是否是金币场
- function ShareView:ctor(shareData,shareCallbakc, dataForUrl,isCoinGame)
- ShareView.super.ctor(self)
-
-
- --房间号
- if app.room and app.room.roomInfo and app.room.roomInfo.nShowTableId then
- self.roomID = app.room.roomInfo.nShowTableId
- end
-
- --游戏规则
- self.gameMode = shareData.gameMode or ""
-
- --分享数据
- shareData.scene = shareData.scene or "talk"
- shareData.contentType = shareData.contentType or "url"
- shareData.title = shareData.title or ""
- local srcDescription = shareData.description
- shareData.description = "<仅供娱乐,严禁赌博>\n"..(shareData.description or "")
- shareData.image = shareData.image or cc.FileUtils:getInstance():getWritablePath().."icon.png"
- shareData.imageWidth = shareData.imageWidth or 100
- --略缩图大小
- shareData.thumbWidth = shareData.thumbWidth or 100
-
- --分享选项
- shareData.menuIdxs = shareData.menuIdxs or {1,2,4,5,6}
-
- local url = app.config.Setting.appDownloadUrl
- local paramGameID
- if shareData and shareData.copyData and shareData.copyData.gameId then
- paramGameID = shareData.copyData.gameId
- end
- local gameID = paramGameID or app.gameId
- local playerID = app.user.loginInfo.uid
- local prefix = "&"
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- if app.room and app.room.roomInfo and app.room.roomInfo.nShowTableId then
- url = string.format(url .. prefix .. "uid=%d&tableId=%d&clubid=%d", playerID, app.room.roomInfo.nShowTableId,app.club_php.clubID)
- else
- url = string.format(url .. prefix .. "uid=%d&clubid=%d", playerID, app.club_php.clubID)
- end
- else
- if app.room and app.room.roomInfo and app.room.roomInfo.nShowTableId then
- url = string.format(url .. prefix .. "uid=%d&tableId=%d", playerID, app.room.roomInfo.nShowTableId)
- else
- url = string.format(url .. prefix .. "uid=%d", playerID)
- end
- end
-
- shareData.url = shareData.url or url
-
- --复制数据
- local copyData=""
- if shareData.copyData then
- dump(shareData.copyData,"-ShareView-")
- --如果是table 2种情况一个是总结算(type=1) 一个是房间内邀请(type=2)
- if type(shareData.copyData)=="table" then
-
- if shareData.copyData.type==1 then
- --总结算格式
- -- copyData={
- -- type=1,
- -- gameId=1,
- -- tableId=123456,
- -- userInofs={
- -- {nickname="xxx",totalScore=0},
- -- {nickname="xxx",totalScore=0},
- -- }
- -- }
-
- --游戏名
- local curGameID = shareData.copyData.gameId or app.gameId
- --local curGameRule = shareData.copyData.gameRule
- local gameName = shareData.gameName or getSubGameName(curGameID) or "悠闲麻将"
- --[[local gameConfig = getSubGameConfig(curGameID)
- if gameConfig and gameConfig.bSingleGame then
- gameName = getSubGameRuleName(curGameID,curGameRule)
- end--]]
- --房间号
- local tableId = shareData.copyData.tableId or app.room.roomInfo.nShowTableId
- --时间
- local endTime = os.date("%Y-%m-%d %X")
-
- --用户数据信息
- local scoreStr=""
- if shareData.copyData.userInfos then
- --金币场机器人userid太大暴露,屏蔽
- if isCoinGame then
- for k,user in pairs(shareData.copyData.userInfos) do
- scoreStr = string.format("%s[%s] %s分\n", scoreStr, user.nickname,user.totalScore>=0 and "+".. user.totalScore or user.totalScore)
- end
- else
- for k,user in pairs(shareData.copyData.userInfos) do
- scoreStr = string.format("%s[%s] %s分\n", scoreStr, getShortName2(user.nickname), user.totalScore>=0 and "+".. user.totalScore or user.totalScore)
- end
- end
-
- end
-
- local endStr = "竞技成绩仅供娱乐,禁止赌博!"
-
- if isCoinGame then --金币场没有房间号
- copyData = string.format("[%s]\n结束时间:%s\n成绩:\n%s\n%s",
- gameName,
- endTime,
- scoreStr,
- endStr)
- else
- copyData = string.format("[%s]\n房间号:%s\n结束时间:%s\n成绩:\n%s\n%s",
- gameName,
- tableId,
- endTime,
- scoreStr,
- endStr)
- end
- elseif shareData.copyData.type==2 then
- --邀请好友格式
- -- copyData={
- -- type=2,
- -- }
-
- local clubData = ""
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- local clubName = ""
- local clubList = app.club_php.clubList
- if clubList and clubList[tonumber(app.club_php.clubID)] then
- clubName = clubList[tonumber(app.club_php.clubID)].clubName;
- clubData = string.format("%s:%s \n",(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME), clubName)
- end
- end
- local tishi = "复制信息打开游戏将自动入座\n<仅供娱乐,严禁赌博>"
- copyData = string.format("%s%s\n%s\n%s",clubData,
- shareData.title,
- srcDescription,
- tishi)
- end
- else
- copyData = shareData.copyData
- end
- end
-
- --保存
- self.gameID = gameID
-
- --防封群分享标志
- self.FFQFlag = shareData.FFQFlag or false
-
- --茶馆id,不在茶馆,则没有此字段
- self.clubID = shareData.ClubID
-
- --需要显示的按钮
- self.menuIdxs = self:getMenuIdxs(shareData)
-
- --分享内容
- self.shareInfo = shareData;
-
- --复制内容
- self.copyData = copyData
-
- --回调函数
- self.shareCallbakc = shareCallbakc
-
- -- 分享战绩链接需要的内容
-
- self.isShareZhanjiUrl = shareData.isShareZhanjiUrl
- self.dataForUrl = dataForUrl or {}
-
- self.zhanjiUrl = app.serverConfigs.clientConfig.webgamb or RomSetting.ZhanJiUrl
- end
-
- function ShareView:onEnter()
- ShareView.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:initWechat();
- -- 复制
- self:initCopy();
- -- 茶馆邀请
- self.ui.Items.Button_club_invite:registerClick(handler(self, self.onClickClubFriends))
-
- -- 战绩网页分享
- self:initShareZhanJiUrl();
-
- self:initData();
-
- end
- function ShareView:getSupportType()
- return {
- WeiXin = {isShowed = true},
- }
- end
- --- ShareView:getMenuIdxs 初始化要显示的分享方式
- function ShareView:getMenuIdxs(shareData)
- local menuIdxs = {}
- local supportType = self:getSupportType()
- for k, v in pairs(supportType or {}) do
- logD("ShareView:getMenuIdxs", k, v.isShowed)
- if v.isShowed then
- if k == "WeiXin" then
- table.insert(menuIdxs, 1);
- end
- end
- end
-
- if shareData.copyData and shareData.copyData ~= "" then
- table.insert(menuIdxs, 2);
- end
-
- if shareData.isShareZhanjiUrl and supportType.WebZhanJi.isShowed then
- table.insert(menuIdxs, 7);
- end
-
- if shareData.isNeedClubShare then
- -- 是否需要亲友圈分享
- table.insert(menuIdxs, 3);
- end
-
- table.sort(menuIdxs, function (a, b)
- return a < b;
- end)
-
- return menuIdxs
- end
- --- ShareView:initWechat 微信分享
- function ShareView:initWechat()
- self.ui.Items.Button_wechat:registerClick(handler(self, self.wechatShare))
- end
-
- --- ShareView:initCopy 复制分享
- function ShareView:initCopy()
- self.ui.Items.Button_copy:registerClick(handler(self, self.onClickCopy))
- end
- --
- function ShareView:initData(isRequest)
- --是否开启微信分享屏蔽
- local isForbidShare = false
- 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 and not isRequest then
- --未找到茶馆列表数据时,请求茶馆列表(可能是断线重连)
- if IS_USER_NEW_CLUB then
- app.waitDialogManager:showWaitNetworkDialog("获取数据中...")
- app.club_php:requestClubList(function()
- app.waitDialogManager:closeWaitNetworkDialog()
- self:initData(true)
- end)
- else
- app.club_php:requestOneClubInfo(app.club_php.clubID);
- end
- end
- end
-
- 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
-
- -- 将需要显示的按钮索引标为 true
- local tt = {}
- for k,idx in pairs(self.menuIdxs) do
- if k == 1 and isForbidShare and (not self.FFQFlag) then--微信分享屏蔽且不是防封群分享就不显示微信按钮
- --微信分享已屏蔽
- tt[idx] = false
- else
- tt[idx] = true
- end
- end
-
- -- 隐藏不相关的按钮
- local index = 0
- for i = 1,8 do
- local name = string.format("Layout_Btn_%d", i)
- local node = self.ui.Items[name]
- if node and not tolua.isnull(node) then
- -- 标记为true的显示
- -- 否则不显示
- if tt[i] then
- node:setVisible(true)
- index = index + 1
- else
- node:setVisible(false)
- end
- end
- end
-
- if index == 0 then
- showTooltip("已关闭微信分享功能,请联系管理员打开!")
- end
-
- -- 重新布局
- self.ui.Items.Layout_btn:requestDoLayout()
- self.ui.Items.Layout_btn:doLayout()
- end
-
- function ShareView:initShareZhanJiUrl()
- local data = self:getSupportType()
- if not data.WebZhanJi.isShowed and not self.isShareZhanjiUrl then --self.isShareZhanjiUrl
- if self.ui.Items.Layout_Btn_7 then
- self.ui.Items.Layout_Btn_7:setVisible(false);
- end
- else
- app.serverConfigs:requestClientConfig(function()
- self.zhanjiUrl = app.serverConfigs.clientConfig.webgamb or RomSetting.ZhanJiUrl
- end)
- end
-
- self.ui.Items.Button_url:registerClick(handler(self, self.onClickShareUrl))
- end
-
- --微信分享
- function ShareView:wechatShare()
- app.plugin:shareGame(self.shareInfo, self.shareCallbakc);
- self:onClickClose();
- end
-
-
- -- 关闭响应函数
- function ShareView:onClickClose()
- playBtnEffect()
- self:removeFromParent()
- end
-
- --复制
- function ShareView:onClickCopy()
- if self.copyData and type(self.copyData) == "string" then
- log("ShareView:onClickCopy() copyData =", self.copyData)
- copyStringToClipboard(self.copyData)
- else
- copyStringToClipboard("")
- end
-
- app.plugin:gotoWeiXin();
- self:onClickClose();
- end
-
- --茶馆邀请
- function ShareView:onClickClubFriends()
- playBtnEffect();
- if app.club_php.clubID and app.club_php.clubID ~= 0 then
- local view = import("luaScript.Views.Club.ClubInvite"):new(self.roomID, self.gameMode)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
-
- self:onClickClose();
- end
-
- function ShareView:onClickShareUrl()
- if not self.zhanjiUrl then
- showTooltip("链接无效,请使用其他分享方式");
- return
- end
-
- local dataForUrl = {
- app = getAppId(),
- uid = self.dataForUrl.uid or app.user.loginInfo.uid,
- gameid = self.dataForUrl.gameid or self.gameID,
- roomid = self.dataForUrl.roomid or app.room.roomInfo.nShowTableId,
- endtime = self.dataForUrl.endtime or os.time(),
- }
-
- local url = string.format("%s?uid=%s&gameid=%s&app=%s&roomid=%s&endtime=%s",
- self.zhanjiUrl,
- dataForUrl.uid,
- dataForUrl.gameid,
- dataForUrl.app,
- dataForUrl.roomid,
- dataForUrl.endtime);
-
- local content = nil;
- if self.shareInfo and self.shareInfo.copyData and self.shareInfo.copyData.userInfos then
- for k,v in pairs(self.shareInfo.copyData.userInfos) do
-
-
- local userInfo = ""
- if v.totalScore > 0 then
- userInfo = string.format("%s(+%s)", getShortName2(v.nickname), v.totalScore)
- else
- userInfo = string.format("%s(%s)", getShortName2(v.nickname), v.totalScore)
- end
- if content then
- content = content .. "," .. userInfo
- else
- content = userInfo
- end
- end
- end
- content = "<仅供娱乐,严禁赌博>\n"..(content or "")
-
- local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
-
- local gameName = self.shareInfo.gameName or getSubGameName(self.gameID) or "悠闲麻将"
-
- local shareInfo =
- {
- contentType = "url",
- scene = "talk",
- url = url,
- title = gameName.."战绩",
- description = content,
- image = imagePath,
- imageWidth = 100,
- };
- dump(shareInfo)
- app.plugin:shareGame(shareInfo, self.shareCallbakc);
-
- end
-
- return ShareView
|