Login.vue 5.7 KB

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