Login.vue 5.3 KB

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