authorize - 副本.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <view>
  3. <!--pages/authorize/authorize.wxml-->
  4. <block v-if="isLong">
  5. <view class="about">
  6. <view class="logo">
  7. <image :src="logo"></image>
  8. <view>{{ name }}</view>
  9. </view>
  10. </view>
  11. <view class="btn">
  12. <button class="login" @click="getWXUserProfile()">授权登录</button>
  13. <!-- <button class="login" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">授权登录</button> -->
  14. <view class="zanbu" @tap="back">暂不登录</view>
  15. <view hover-class="none" class="xieyi ddflex">
  16. <view @click="jump('/mine/page/page?title=用户协议&isXieyi=true')">《用户协议》</view>
  17. <view @click="jump('/mine/page/page?title=隐私声明&isYinsi=true')">《隐私声明》</view>
  18. </view>
  19. <view class="copy" v-if="about.name && about.recordNumber">{{ about.name ? about.name : '' }}版权所有© {{ about.recordNumber ? about.recordNumber : '' }}</view>
  20. </view>
  21. </block>
  22. <block v-if="isphone">
  23. <view class="phone">
  24. <view class="logo">
  25. <image :src="logo"></image>
  26. <view>{{ name }}</view>
  27. </view>
  28. </view>
  29. <view class="btn">
  30. <button class="btnphone" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信手机号快捷绑定</button>
  31. <!-- <view class="btngophone r10">手机号验证绑定</view> -->
  32. <view class="zanbu" @tap="back">暂不绑定</view>
  33. <view hover-class="none" class="xieyi ddflex">
  34. <view @click="jump('/mine/page/page?title=用户协议&isXieyi=true')">《用户协议》</view>
  35. <view @click="jump('/mine/page/page?title=隐私声明&isYinsi=true')">《隐私声明》</view>
  36. </view>
  37. <view class="copy" v-if="about.name && about.recordNumber">{{ about.name ? about.name : '' }}版权所有© {{ about.recordNumber ? about.recordNumber : '' }}</view>
  38. </view>
  39. <!-- 绑定手机号 -->
  40. <!-- <block>
  41. <view class='phone'>
  42. <view class='logo'>
  43. <image src='{{about.logo}}'></image>
  44. </view>
  45. </view>
  46. <view class="bgfff form r10">
  47. <view class="borbom dflex"><image src="/pages/images/telephone.png"></image><input type="text" placeholder="请输入手机号" /></view>
  48. <view class="dflex paw"><image src="/pages/images/paw.png"></image><input type="text" placeholder="请输入验证码" /><text class="huoqu">获取验证码</text></view>
  49. </view>
  50. <view class="btn">
  51. <button class="goloing">立即登录</button>
  52. <view class="gophone1 r10">微信手机号快捷绑定</view>
  53. <navigator url="/mine/page/page?title=用户协议&isXieyi=true" hover-class="none" class="xieyi">《用户协议》</navigator>
  54. <view class='copy'>{{about.name}}版权所有© {{about.recordNumber}}</view>
  55. </view>
  56. </block> -->
  57. </block>
  58. <view class="ceng" v-if="isXyShow"></view>
  59. <view class="pop-protocol" :style="'bottom:' + XyBottom">
  60. <view class="pop-tit">个人隐私保护指引</view>
  61. <view class="pop-con">
  62. 为更好的保障你的个人信息安全及权利行使。我们将通过
  63. <text @click="jump('/mine/page/page?title=用户协议&isXieyi=true')">《用户协议》</text>
  64. <text @click="jump('/mine/page/page?title=隐私声明&isYinsi=true')">《隐私声明》</text>
  65. 帮助你了解我们收集、使用、存储、公开披露个人信息的情况。请仔细阅读并理解本政策的内容,若你同意,请点击下方按钮开始接受我们的服务。
  66. </view>
  67. <view class="pop-btn">
  68. <view class="pop-agree" @click="agn()">同意并继续</view>
  69. <view class="pop-no" @click="back()">不同意并退出</view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. // pages/authorize/authorize.js
  76. const app = getApp();
  77. const req = require('../../utils/request.js');
  78. export default {
  79. data() {
  80. return {
  81. sessionKey: '',
  82. openid: '',
  83. about: {},
  84. isShow: true,
  85. isphone: false,
  86. isLong: true,
  87. istetphone: 0,
  88. configRes: {},
  89. logo: '',
  90. name: '',
  91. isPromote: false, //是否从分销进入
  92. isXyShow: true ,//默认显示协议指引
  93. XyBottom: '-100%',
  94. };
  95. },
  96. components: {},
  97. props: {},
  98. onLoad: function(options) {
  99. var agnXY = req.getStorage('agnXY');
  100. if (agnXY) {
  101. this.isXyShow = false;
  102. this.XyBottom = '-100%';
  103. }else{
  104. setTimeout(res=>{
  105. this.XyBottom = 0;
  106. },200)
  107. }
  108. app.globalData.getCheckSessoin(json => {
  109. this.sessionKey = json.session_key;
  110. this.openid = json.openid;
  111. });
  112. console.log('登录页面===********************' + JSON.stringify(options));
  113. if (req.getStorage('configRes')) {
  114. let configRes = JSON.parse(req.getStorage('configRes'));
  115. this.setData({
  116. istetphone: configRes.user_bind_mobile,
  117. logo: configRes.CONFIG_PROJECT_LOGO,
  118. name: configRes.CONFIG_PROJECT_TITLE
  119. });
  120. } else {
  121. req.g('/api/config', res => {
  122. req.setStorage('configRes', JSON.stringify(res));
  123. this.setData({
  124. istetphone: res.user_bind_mobile,
  125. logo: res.CONFIG_PROJECT_LOGO,
  126. name: res.CONFIG_PROJECT_TITLE
  127. });
  128. });
  129. }
  130. if (options.bindmobile == 1) {
  131. this.isphoneFun();
  132. }
  133. if (options.scene) {
  134. this.scene = options.scene;
  135. this.loadCodeParams();
  136. }
  137. this.getAbout();
  138. // this.isphone()
  139. },
  140. onShow: function() {
  141. uni.setNavigationBarColor({
  142. frontColor: '#000000',
  143. backgroundColor: '#FFFFFF'
  144. });
  145. uni.setNavigationBarTitle({
  146. title: '授权登录'
  147. }); // this.isshop()
  148. },
  149. onUnload: function() {
  150. // 调用登录的时候会存一个REDIRECT_URL 根据REDIRECT_URL来判断用户是从哪里登录,identification用户点击暂不绑定的标识
  151. // console.log(this.identification,req.getStorage('REDIRECT_URL'),app)
  152. if (req.getStorage('REDIRECT_URL') == '/pages/user/user' && !this.identification) {
  153. // 判断是否开启了强制绑定手机号,并且判断缓存是否有userInfo,是否存在userInfo.mobile电话
  154. if (this.istetphone == '1' && req.getStorage('userInfo') && !req.getStorage('userInfo').mobile) {
  155. let pages = getCurrentPages();
  156. var prevPage = pages[pages.length - 2];
  157. prevPage.$vm.setData({
  158. noLogin: true
  159. });
  160. uni.navigateBack({
  161. delta: -1
  162. });
  163. // app.globalData.switchTab('pages/index/index')
  164. }
  165. // 判断用户是否登录,点击返回键,就跳转到首页,并传个值到user页面,阻止调用接口,防止登录
  166. if (!req.getStorage('userInfo')) {
  167. let pages = getCurrentPages();
  168. var prevPage = pages[pages.length - 2];
  169. prevPage.$vm.setData({
  170. noLogin: true
  171. });
  172. uni.navigateBack({
  173. delta: -1
  174. });
  175. // app.globalData.switchTab('pages/index/index')
  176. }
  177. }
  178. },
  179. methods: {
  180. jump(url) {
  181. uni.navigateTo({
  182. url: url
  183. });
  184. },
  185. loadCodeParams() {
  186. let _ts = this;
  187. return new Promise((resolve, reject) => {
  188. if (!_ts.scene) {
  189. resolve();
  190. return false;
  191. }
  192. req.getRequest(
  193. '/api/code/params',
  194. {
  195. scene: _ts.scene
  196. },
  197. data => {
  198. if (data.scene.split('_')[1] == 'isPromote') {
  199. this.isPromote = true;
  200. }
  201. // console.log("获取用户id====++++++++++++++" + JSON.stringify(data));
  202. req.setStorage('pidCode', data.userId);
  203. resolve();
  204. }
  205. );
  206. });
  207. },
  208. agn() {
  209. this.isXyShow = false;
  210. this.XyBottom = '-100%';
  211. req.setStorage('agnXY', true);
  212. },
  213. back() {
  214. this.XyBottom = '-100%';
  215. this.identification = true;
  216. // uni.switchTab({
  217. // url: req.header.appId=='ZQ1VK5oc17I387E'?'/pages/timelyDelivery/index':'/pages/index/index'
  218. // });
  219. if (this.isPromote) {
  220. uni.switchTab({
  221. url: req.header.appId == 'ZQ1VK5oc17I387E' ? '/pages/timelyDelivery/index' : '/pages/index/index'
  222. });
  223. } else {
  224. uni.navigateBack();
  225. }
  226. },
  227. getAbout() {
  228. var _this = this;
  229. req.getRequest(
  230. '/api/aboutAs',
  231. {},
  232. function(res) {
  233. _this.setData({
  234. about: res
  235. });
  236. },
  237. true
  238. );
  239. },
  240. getWXUserProfile() {
  241. let that = this;
  242. try {
  243. uni.getUserProfile({
  244. desc: '注册',
  245. success: res => {
  246. // console.log('数据====', JSON.stringify(res));
  247. that.toSubmitLogin(res.iv, res.encryptedData);
  248. },
  249. fail: res => {
  250. // console.log('数据====', res);
  251. req.msg(res);
  252. }
  253. });
  254. } catch (e) {
  255. // 老版
  256. wx.getUserInfo({
  257. success: function(ress) {
  258. // console.log('getUserInfo====', JSON.stringify(ress));
  259. that.toSubmitLogin(ress.iv, ress.encryptedData);
  260. }
  261. });
  262. }
  263. },
  264. toSubmitLogin(iv, encryptedData) {
  265. let that = this;
  266. if (!encryptedData || !iv) return false;
  267. let _params = {
  268. sessionKey: this.sessionKey,
  269. openId: this.openid,
  270. iv: iv,
  271. encryptedData: encryptedData
  272. };
  273. if (req.getStorage('pidCode')) {
  274. _params.parentId = req.getStorage('pidCode');
  275. }
  276. req.postRequest('/api/login', _params, json => {
  277. let params = json;
  278. // console.log(json);
  279. that.setData(params);
  280. let url = req.getStorage('REDIRECT_URL');
  281. req.setStorage('userInfo', json);
  282. // req.removeStorage('MERCHANT')
  283. if (that.scene) {
  284. that.back();
  285. } else {
  286. // console.log(json.mobile);
  287. if (that.istetphone != '1') {
  288. uni.navigateBack();
  289. } else {
  290. if (json.mobile) {
  291. uni.navigateBack();
  292. } else {
  293. that.isphoneFun();
  294. }
  295. }
  296. }
  297. that.isshop();
  298. });
  299. },
  300. //原来的登录
  301. bindGetUserInfo(e) {
  302. var that = this;
  303. let data = e.detail;
  304. if (!data.encryptedData || !data.iv) return false;
  305. let _params = {
  306. sessionKey: this.sessionKey,
  307. iv: data.iv,
  308. encryptedData: data.encryptedData
  309. }; // console.log("!!!!!!!!!!!!!!!!!!!!!!"+_params)
  310. if (req.getStorage('pidCode')) {
  311. _params.parentId = req.getStorage('pidCode');
  312. }
  313. // console.log("登录页面===" + JSON.stringify(_params));
  314. req.postRequest('/api/login', _params, json => {
  315. let params = json;
  316. // console.log(json);
  317. that.setData(params);
  318. let url = req.getStorage('REDIRECT_URL');
  319. req.setStorage('userInfo', json);
  320. // req.removeStorage('MERCHANT')
  321. if (that.scene) {
  322. that.back();
  323. } else {
  324. // console.log(json.mobile);
  325. if (that.istetphone != '1') {
  326. uni.navigateBack();
  327. } else {
  328. if (json.mobile) {
  329. uni.navigateBack();
  330. } else {
  331. that.isphoneFun();
  332. }
  333. }
  334. }
  335. that.isshop();
  336. });
  337. },
  338. //判断是否开启手机绑定
  339. isphoneFun() {
  340. this.setData({
  341. isphone: true,
  342. isLong: false
  343. });
  344. uni.setNavigationBarTitle({
  345. title: '绑定手机号'
  346. });
  347. },
  348. getPhoneNumber(e) {
  349. let that = this;
  350. let _params = {
  351. sessionKey: this.sessionKey,
  352. iv: e.detail.iv,
  353. encryptedData: e.detail.encryptedData
  354. };
  355. // console.log(e.detail.errMsg);
  356. if (req.getStorage('pidCode')) {
  357. _params.parentId = req.getStorage('pidCode');
  358. }
  359. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  360. req.postRequest('/api/weixin/mobile', _params, json => {
  361. // console.log(json);
  362. if (json.mobile) {
  363. var userInfo = req.getStorage('userInfo');
  364. userInfo.mobile = json.mobile;
  365. req.setStorage('userInfo', userInfo);
  366. if (that.scene) {
  367. that.back();
  368. } else {
  369. uni.navigateBack();
  370. }
  371. }
  372. });
  373. } else {
  374. }
  375. },
  376. // 分销的配置
  377. isshop() {
  378. req.p('/api/distribution/config', data => {
  379. // console.log(data);
  380. req.setStorage('distribution', data);
  381. });
  382. }
  383. }
  384. };
  385. </script>
  386. <style>
  387. @import './authorize.css';
  388. </style>