authorize.vue 12 KB

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