login.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view class="login-content">
  3. <view class="login-content-info">
  4. <view class="login-bgm":style="{backgroundImage:`url(${staticUrl}/img/tuan-index-bg.png)`}">
  5. <image class="login-logo" :src="staticUrl+'/img/logo.png'" mode="scaleToFill"></image>
  6. <text>{{ title }}</text>
  7. </view>
  8. <view class="login-info">
  9. <view class="login-info-box">
  10. <text class="login-info-title">账号密码登陆</text>
  11. <view class="login-info-form">
  12. <u--form
  13. labelWidth="0"
  14. :borderBottom="false"
  15. :model="form"
  16. :rules="rules"
  17. ref="uForm">
  18. <u-form-item prop="mobile">
  19. <u--input
  20. v-model="form.mobile"
  21. placeholder="请输入账号"
  22. border="surround"
  23. shape="circle"
  24. prefixIcon="account-fill"
  25. prefixIconStyle="font-size: 22px;color: #909399"
  26. ></u--input>
  27. </u-form-item>
  28. <u-form-item prop="password">
  29. <u--input
  30. v-model="form.password"
  31. placeholder="请输入账密码"
  32. border="surround"
  33. shape="circle"
  34. prefixIcon="lock-fill"
  35. :password="true"
  36. prefixIconStyle="font-size: 22px;color: #909399"
  37. ></u--input>
  38. </u-form-item>
  39. </u--form>
  40. </view>
  41. <view class="login-info-submit">
  42. <u-button
  43. class="login-info-submit-but"
  44. @click="submit()"
  45. :loading="loading"
  46. loadingText="登录中..."
  47. >登录</u-button>
  48. </view>
  49. <view class="login-info-tip">暂不支持自行注册</view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. export default {
  57. data() {
  58. return {
  59. code:'',
  60. staticUrl:this.$commonConfig.staticUrl,
  61. title: '《伟大转折》剧目团购系统',
  62. logoUrl: this.$commonConfig.staticUrl + "login/logo.png",
  63. loading: false,
  64. backUrl:null,
  65. form: {
  66. mobile: '',
  67. password: '',
  68. },
  69. rules: {
  70. 'mobile': {
  71. type: 'string',
  72. required: true,
  73. message: '请填写账号',
  74. trigger: ['blur', 'change']
  75. },
  76. 'password': {
  77. type: 'string',
  78. required: true,
  79. message: '请填写密码',
  80. trigger: ['blur', 'change']
  81. },
  82. },
  83. }
  84. },
  85. onReady() {
  86. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  87. this.$refs.uForm.setRules(this.rules)
  88. },
  89. onLoad(e) {
  90. let that = this;
  91. if(!e.code) { // 微信第三方登录失败
  92. this.redirectToAuth()
  93. }else {
  94. this.code = e.code
  95. }
  96. // 测试环境填充用户名密码
  97. if(process.env.NODE_ENV=='development'){
  98. this.form.mobile = '13682277062';
  99. this.form.password = '123456';
  100. }
  101. uni.getStorage({
  102. key: 'backUrl',
  103. success: function (res) {
  104. // console.log('getStorage',res);
  105. },
  106. complete(res) {
  107. if(res.data){
  108. that.backUrl = '/'+res.data;
  109. }else{
  110. that.backUrl = '/pages/index/index';
  111. }
  112. console.log('backUrl',that.backUrl);
  113. }
  114. });
  115. },
  116. onShow() {
  117. },
  118. methods: {
  119. /** 公众号 微信授权登录 */
  120. redirectToAuth() {
  121. window.location.href = this.$commonConfig.authUrl;
  122. },
  123. /**
  124. *
  125. * 提交登录
  126. *
  127. */
  128. async submit(e) {
  129. let _this = this;
  130. let wxinfo = null
  131. let data = {}
  132. wxinfo = await this.$u.api.wxinfoH5({code:this.code});
  133. let { openid } = wxinfo.data;
  134. this.form.h5OpenId = openid;
  135. this.loading = true
  136. this.$refs.uForm.validate().then(res => {
  137. this.$u.toast('校验通过')
  138. this.$u.api.teamLogin(this.form).then(res=>{
  139. this.loading = false
  140. // console.log('res',res.data);
  141. this.$u.vuex('vuex_user_info', res.data);
  142. uni.reLaunch({url: this.backUrl});
  143. }).catch(err=>{
  144. console.log('login',err);
  145. this.$u.toast(err.msg)
  146. setTimeout(()=>{
  147. this.redirectToAuth();
  148. },1500)
  149. this.loading = false
  150. })
  151. }).catch(errors => {
  152. this.$u.toast('校验失败')
  153. this.loading = false
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .login-content {
  161. width: 100%;
  162. height: 100vh;
  163. position: relative;
  164. box-sizing: border-box;
  165. --bgm-height: 630rpx;
  166. }
  167. /** 背景 */
  168. .login-content-box {
  169. width: 100%;
  170. height: 100%;
  171. box-sizing: border-box;
  172. }
  173. .login-bgm {
  174. width: 100%;
  175. height: 630rpx;
  176. // background-image: url("#{$image-beas-url}login/bgm.png");
  177. background-size: 100% auto;
  178. background-repeat: no-repeat;
  179. box-sizing: border-box;
  180. display: flex;
  181. flex-direction: column;
  182. justify-content: center;
  183. align-items: center;
  184. .login-logo {
  185. width: 240rpx;
  186. height: 172rpx;
  187. padding: 50rpx 0;
  188. }
  189. >text {
  190. font-size: 32rpx;
  191. font-family: SourceHanSansCN, SourceHanSansCN;
  192. font-weight: bold;
  193. color: #FFD788;
  194. }
  195. }
  196. .login-info {
  197. width: 100%;
  198. height: calc(100% - var(--bgm-height) + 40rpx);
  199. background-color: #fff;
  200. border-radius: 28rpx 28rpx 0rpx 0rpx;
  201. position: absolute;
  202. bottom: 0;
  203. left: 0;
  204. z-index: 22;
  205. box-sizing: border-box;
  206. padding: 80rpx;
  207. .login-info-box {
  208. width: 100%;
  209. height: 100%;
  210. display: flex;
  211. flex-direction: column;
  212. box-sizing: border-box;
  213. .login-info-title {
  214. font-size: 32rpx;
  215. font-family: SourceHanSansCN, SourceHanSansCN;
  216. font-weight: bold;
  217. color: #2D2D2D;
  218. padding-bottom: 40rpx;
  219. }
  220. .login-info-form {
  221. }
  222. .login-info-submit {
  223. width: 100%;
  224. height: 80rpx;
  225. padding: 40rpx 0 20rpx;
  226. flex-shrink: 0;
  227. .login-info-submit-but {
  228. display: flex;
  229. justify-content: center;
  230. align-items: center;
  231. border-radius: 40rpx;
  232. width: 100% !important;
  233. height: 100% !important;
  234. background-color: #ed0000;
  235. color: #fff;
  236. }
  237. }
  238. .login-info-tip {
  239. width: 100%;
  240. text-align: center;
  241. font-size: 24rpx;
  242. font-family: SourceHanSansCN, SourceHanSansCN;
  243. font-weight: 400;
  244. color: #C2C2C2;
  245. }
  246. }
  247. }
  248. </style>