c-pop-auth.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <view class="mask" catchtouchmove="true" :class="maskState===0 ? 'none' : maskState===1 ? 'show' : ''" @click.stop="maskClickHandel">
  3. <view class="mask-content" @click.stop.prevent="stopPrevent">
  4. <view class="mask-content-inner">
  5. <view class="head">
  6. <view class="icon" hover-class="hover" hover-stay-time="100" @click="maskClickHandel">
  7. <u-icon name="arrow-left" color="#000" size="28"></u-icon>
  8. </view>
  9. <view class="head__text">用户登陆</view>
  10. </view>
  11. <view class="body">
  12. <view class="autho-info">获取微信用户信息</view>
  13. <view class="explain-info">
  14. <text class="text">为了更好的为您服务,需要获取您的头像和昵称</text>
  15. </view>
  16. </view>
  17. <view class="action-wrap">
  18. <u-button type="primary" openType="getUserInfo" @getuserinfo="getUserInfo" shape="round" size="large" text="微信用户一键登录" @click="getUserInfo2"></u-button>
  19. </view>
  20. <view class="action-msg">
  21. <c-radio v-model="isAuth"></c-radio>
  22. <view class="action-msg-textwrap" style="padding-left: 10rpx;">
  23. <text class="text-info" style="margin-left: 0rpx;" @click="isAuth = !isAuth">登录代表您已同意</text>
  24. <text class="text-warning" style="margin-left: 10rpx;" @click="getContract(1)">《服务协议》</text>
  25. <text class="text-info">、</text>
  26. <text class="text-warning" style="margin-left: 10rpx;" @click="getContract(2)">《隐私政策》</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- <u-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-code> -->
  32. <u-toast ref="uToast"></u-toast>
  33. </view>
  34. </template>
  35. <script>
  36. import { mapActions, mapState, mapGetters } from 'vuex';
  37. export default {
  38. name:"c-pop-auth",
  39. data() {
  40. return {
  41. maskState: 0,
  42. isAuth: false,
  43. tips: '获取验证码',
  44. seconds: 60,
  45. send: false,
  46. form: {
  47. phone: '',
  48. code: '',
  49. }
  50. };
  51. },
  52. props: {
  53. onComplate: {
  54. type: Function,
  55. default(){
  56. return () => { }
  57. }
  58. },
  59. },
  60. computed: {
  61. ...mapGetters(['isLogin'])
  62. },
  63. mounted() {
  64. },
  65. methods: {
  66. ...mapActions({
  67. 'login': 'login',
  68. 'loginRefresh': 'loginRefresh',
  69. 'cacheUserInfo': 'cacheUserInfo',
  70. 'unCacheUserInfo': 'unCacheUserInfo',
  71. }),
  72. stopPrevent(){
  73. },
  74. toggleMask(type){
  75. let timer = type === 'show' ? 10 : 0;
  76. let state = type === 'show' ? 1 : 0;
  77. // this.maskState = 2;
  78. // setTimeout(()=>{
  79. // this.maskState = state;
  80. // }, timer)
  81. this.maskState = state;
  82. },
  83. /**
  84. * @description 确认
  85. * @param {Object} title: String desc: String
  86. */
  87. $confirm(options = {}){
  88. console.log("启动权限校验")
  89. this.appInstance = getApp()
  90. // 继承原来的
  91. // this.defautlOptions = Object.assign(this.defautlOptions, options);
  92. return new Promise((resolve,reject)=> {
  93. if(!this.isLogin){
  94. wx.hideTabBar()
  95. this.toggleMask('show')
  96. }
  97. console.log(this.appInstance)
  98. // wx 事件监听确认
  99. this.appInstance._confirm = () => {
  100. resolve(1)
  101. this._confirm = null;
  102. }
  103. // wx 事件监听取消
  104. this.appInstance._cancel = () => {
  105. resolve(0)
  106. this._cancel = null;
  107. }
  108. console.log(this.isLogin, '用户判断是否')
  109. if(this.isLogin){
  110. this.confirm()
  111. return
  112. }
  113. if(this.appInstance.isTongyi){
  114. this.unCacheUserInfo({}).then(res => {
  115. // 直接登陆
  116. if(res == 2){
  117. this.confirm();
  118. this.toggleMask();
  119. this.onComplate();
  120. } else {
  121. this.toggleMask();
  122. this.onComplate();
  123. }
  124. })
  125. }
  126. })
  127. },
  128. confirm() {
  129. wx.showTabBar()
  130. // 发送事件
  131. if(this.appInstance._confirm){
  132. this.appInstance._confirm()
  133. this.toggleMask();
  134. }
  135. },
  136. cancel() {
  137. wx.showTabBar()
  138. // 发送事件
  139. if(this.appInstance._cancel){
  140. this.appInstance._cancel()
  141. this.toggleMask();
  142. }
  143. },
  144. getUserInfo2(e) {
  145. if(this.isAuth){
  146. uni.getUserProfile({
  147. desc: "用于完善会员资料",
  148. lang: "zh_CN",
  149. success: (e) => {
  150. // 已经获取过
  151. this.appInstance.isTongyi = true;
  152. console.log('-----允许获取用户信息------')
  153. this.$refs.uToast.show({
  154. type: 'loading',
  155. message: '正在登录,请稍后',
  156. })
  157. this.cacheUserInfo({detail: e}).then(res => {
  158. this.$refs.uToast.hide()
  159. // uni.$u.toast('登录成功')
  160. // if(res.code == 1){
  161. // // 这里此提示会被this.start()方法中的提示覆盖
  162. // // 通知验证码组件内部开始倒计时
  163. // this.$refs.uCode.start()
  164. // }
  165. // 直接登陆
  166. if(res == 2){
  167. this.confirm();
  168. this.toggleMask();
  169. this.onComplate();
  170. } else {
  171. this.toggleMask();
  172. this.onComplate();
  173. }
  174. })
  175. },
  176. fail: (e) => {
  177. console.log('-----拒绝获取用户信息------')
  178. console.log(e)
  179. }
  180. })
  181. } else {
  182. uni.$u.toast('需要同意协议')
  183. }
  184. },
  185. async getUserInfo(e) {
  186. // const {userInfo, signature} = e.detail;
  187. // // 如果同意登陆 表示可以登录
  188. // wx.getUserProfile((e) => {
  189. // console.log(e)
  190. // })
  191. // return
  192. },
  193. maskClickHandel(e) {
  194. this.cancel()
  195. },
  196. getContract(type){
  197. this.$u.route({
  198. url: '/pages/signs/contract/contract',
  199. type: "navigateTo",
  200. params: {
  201. type: type
  202. }
  203. })
  204. },
  205. end() {
  206. this.send = false;
  207. },
  208. start() {
  209. this.send = true;
  210. },
  211. loginAction() {
  212. }
  213. },
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .mask{
  218. display: flex;
  219. flex-direction: column;
  220. align-items: flex-end;
  221. justify-content: flex-end;
  222. position: fixed;
  223. left: 0;
  224. top: var(--window-top);
  225. bottom: 0;
  226. width: 100vw;
  227. height: 100vh;
  228. background: rgba(0,0,0,0);
  229. z-index: 10001;
  230. transition: .3s;
  231. .mask-content{
  232. background-color: #fff;
  233. width: 100vw;
  234. align-self: stretch;
  235. min-height: 597rpx;
  236. transform: translateY(1597rpx);
  237. }
  238. &.none{
  239. display: none;
  240. }
  241. &.show{
  242. background: rgba(0,0,0,.6);
  243. .mask-content{
  244. transform: translateY(0);
  245. }
  246. }
  247. .mask-content-inner{
  248. position: relative;
  249. display: flex;
  250. flex-direction: column;
  251. align-items: center;
  252. .head{
  253. align-self: stretch;
  254. padding: 0 15rpx;
  255. display: flex;
  256. align-items: center;
  257. height: 94rpx;
  258. border-bottom: 1px solid #efefef;
  259. .icon{
  260. display: flex;
  261. justify-content: center;
  262. align-content: center;
  263. width: 60rpx;
  264. height: 60rpx;
  265. margin-right: 30rpx;
  266. &.hover{
  267. background-color: #efefef;
  268. }
  269. }
  270. .head__text{
  271. font-size: 32rpx;
  272. color: #333;
  273. }
  274. }
  275. .body{
  276. align-self: stretch;
  277. padding-top: 40rpx;
  278. padding-left: 30rpx;
  279. padding-right: 30rpx;
  280. display: flex;
  281. flex-direction: column;
  282. .autho-info{
  283. font-size: 38rpx;
  284. color: #000;
  285. font-weight: 500;
  286. }
  287. .explain-info{
  288. padding-top: 15rpx;
  289. padding-left: 10rpx;
  290. .text{
  291. color: #999;
  292. font-size: 24rpx;
  293. }
  294. .link{
  295. color: #FD8701;
  296. font-size: 24rpx;
  297. }
  298. }
  299. }
  300. .action-wrap{
  301. margin-top: 60rpx;
  302. padding: 0 30rpx;
  303. align-self: stretch;
  304. }
  305. .action-msg{
  306. margin-top: 10rpx;
  307. display: flex;
  308. padding: 0 40rpx;
  309. flex-direction: row;
  310. align-items: center;
  311. .action-msg-textwrap{
  312. display: flex;
  313. flex-direction: row;
  314. flex-wrap: wrap;
  315. display: flex;
  316. flex-direction: row;
  317. font-size:24rpx;
  318. }
  319. }
  320. }
  321. }
  322. .c-button {
  323. color: #fff;
  324. width: 510rpx;
  325. margin-top: 20rpx;
  326. }
  327. .c-input-wrap{
  328. margin: 0 auto;
  329. width: 510rpx;
  330. height: 70rpx;
  331. background-color: #F0F2F4;
  332. border-radius: 35px;
  333. padding: 0 14px;
  334. box-sizing: border-box;
  335. margin-bottom: 30rpx;
  336. display: flex;
  337. align-items: center;
  338. .divide{
  339. width: 1px;
  340. height: 40rpx;
  341. border-left: 1px solid #FD8701;
  342. }
  343. .tip-btn{
  344. text-align: center;
  345. min-width: 178rpx;
  346. flex-shrink: 0;
  347. font-size: 24rpx;
  348. font-family: PingFang SC;
  349. font-weight: 500;
  350. color: #FD8701;
  351. &.disable{
  352. color: #999;
  353. }
  354. }
  355. & /deep/ .inner_input{
  356. display: flex;
  357. height: 100%;
  358. }
  359. }
  360. </style>