Login.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="content">
  3. <image class="logo" src="/static/icons/logo.png"></image>
  4. <view class="title">
  5. {{$t('login.title')}}
  6. </view>
  7. <form @submit="loginSubmit">
  8. <view class="section">
  9. <input class="input-account" name="username" :placeholder="$t('login.username')" />
  10. </view>
  11. <view class="section">
  12. <input class="input-pwd" password name="password" :placeholder="$t('login.password')" />
  13. </view>
  14. <view class="btn-area">
  15. <button type="primary" formType="submit" :loading="isLoading">{{loginBtnLabel}}</button>
  16. </view>
  17. </form>
  18. <!-- 第三方登录H5不支持,所以隐藏掉 -->
  19. <!-- #ifndef H5 -->
  20. <view class="third-wapper">
  21. <view class="third-line">
  22. <view class="single-line">
  23. <view class="line"></view>
  24. </view>
  25. <view class="third-words">绑定微信一键登录</view>
  26. <view class="single-line">
  27. <view class="line"></view>
  28. </view>
  29. </view>
  30. <view class="third-icos-wapper">
  31. <!-- 5+app 用qq/微信/微博 登录 小程序用微信小程序登录 h5不支持 -->
  32. <!-- #ifdef MP-WEIXIN -->
  33. <button open-type='getUserInfo' @getuserinfo="wxLogin" class="third-btn-ico">
  34. </button>
  35. <!-- #endif -->
  36. </view>
  37. </view>
  38. <!-- #endif -->
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import {
  44. mapState
  45. } from 'vuex';
  46. export default {
  47. data() {
  48. return {
  49. parm: {
  50. avatarUrl: "",
  51. nickName: "",
  52. openId: ""
  53. }
  54. };
  55. },
  56. computed: {
  57. ...mapState(['isLoading']),
  58. loginBtnLabel() {
  59. return this.isLoading ? '' : this.$t('login.login');
  60. }
  61. },
  62. methods: {
  63. loginSubmit(event) {
  64. uni.hideKeyboard();
  65. const {
  66. value: loginForm
  67. } = event.detail;
  68. this.$store.dispatch('login', loginForm)
  69. .then(_ => {
  70. //标记刚登录跳转
  71. uni.setStorageSync('test', '1');
  72. uni.reLaunch({
  73. url: '/pages/Charts/mainStatistics',
  74. });
  75. });
  76. },
  77. // 实现在微信小程序端的微信登录
  78. async wxLogin(e) {
  79. var serverUrl = this.serverurl;
  80. // 通过微信开发能力,获得微信用户的基本信息
  81. var userInfo = e.detail.userInfo;
  82. var parm1 = '';
  83. // 实现微信登录
  84. await uni.login({
  85. provider: "weixin",
  86. success:(loginResult)=> {
  87. // 获得微信登录的code:授权码
  88. var code = loginResult.code;
  89. var openid = "";
  90. uni.request({
  91. url: serverUrl+"/TWeixin/getOpenid?code="+code,
  92. mothod: "GET",
  93. success: (userResult) => {
  94. openid = userResult.data.data;
  95. var parm = {
  96. avatarUrl: "",
  97. nickName: "",
  98. openId: ""
  99. };
  100. parm['avatarUrl'] = userInfo.avatarUrl;
  101. parm['nickName'] = userInfo.nickName;
  102. parm['openId'] = openid;
  103. uni.setStorageSync("newparm", parm);
  104. this.loginweixin();
  105. }
  106. });
  107. }
  108. });
  109. },
  110. loginweixin() {
  111. var parm = uni.getStorageSync("newparm");
  112. if (parm.openId != null) {
  113. this.$store.dispatch('loginWX', parm)
  114. .then(data => {
  115. var result = data.message;
  116. var userInfo = data.data;
  117. if (result == "off") {
  118. uni.setStorageSync("weixinInfo", userInfo);
  119. //没有绑定,跳转到微信绑定页面
  120. uni.reLaunch({
  121. url: "loginWeixin",
  122. });
  123. };
  124. if (result == "SUCCESS") {
  125. // uni.setStorageSync("weixinInfo", weixinInfo);
  126. uni.setStorageSync('test', '1');
  127. uni.reLaunch({
  128. url: '/pages/Charts/mainStatistics',
  129. });
  130. uni.setStorageSync("globalUser", userInfo);
  131. }
  132. });
  133. }
  134. },
  135. }
  136. }
  137. </script>
  138. <style lang="scss">
  139. page {
  140. padding: 200upx 0 0 0;
  141. background-image: url('~@/static/backgrounds/login_bg.png');
  142. background-repeat: no-repeat;
  143. background-size: 100% 100%;
  144. position: absolute;
  145. top: 0;
  146. left: 0;
  147. right: 0;
  148. bottom: 0;
  149. .content {
  150. padding: 0 20upx;
  151. display: flex;
  152. flex-flow: column nowrap;
  153. align-items: center;
  154. .logo {
  155. width: 401upx;
  156. height: 125upx;
  157. text-align: center;
  158. margin: 50upx;
  159. }
  160. form {
  161. width: calc(100% - 100upx);
  162. padding: 50upx;
  163. .section {
  164. margin: 50upx 0;
  165. }
  166. .btn-area {
  167. margin-top: 100upx;
  168. button {
  169. background-color: $uni-color-primary;
  170. }
  171. }
  172. }
  173. }
  174. }
  175. /* 第三方登录 start */
  176. .third-wapper {
  177. width: 100%;
  178. /* 固定底部 */
  179. /* bottom: 0;
  180. position: fixed; */
  181. margin-top: 60upx;
  182. }
  183. .third-line {
  184. display: flex;
  185. flex-direction: row;
  186. justify-content: center
  187. }
  188. .third-words {
  189. color: #A9A9A9;
  190. font-size: 13px;
  191. display: flex;
  192. flex-direction: column;
  193. justify-content: center;
  194. }
  195. .single-line {
  196. padding: 15upx 20upx;
  197. width: 25%;
  198. align-items: center;
  199. }
  200. .third-icos-wapper {
  201. margin-top: 30upx;
  202. display: flex;
  203. flex-direction: row;
  204. justify-content: center
  205. }
  206. .third-ico {
  207. width: 60upx;
  208. height: 60upx;
  209. }
  210. .third-btn-ico {
  211. // background-image:url(http://122.152.205.72:88/group1/M00/00/05/CpoxxFxFO-yAOjTaAAATCIZEzRU503.png);
  212. background-image: url('~@/static/backgrounds/weixin.png');
  213. width: 120upx;
  214. height: 120upx;
  215. background-color: white;
  216. background-size: 120upx 120upx;
  217. // background-repeat:no-repeat;
  218. border: none;
  219. padding: 0;
  220. }
  221. button::after {
  222. border: none;
  223. }
  224. /* 第三方登录 end */
  225. </style>