Login.vue 5.7 KB

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