Login.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="content">
  3. <image class="logo" src="/static/icons/logo.png"></image>
  4. <view class="title">
  5. 管理后台
  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 appid = "wx3844925af1740a7d";
  95. var secret = "c1f0363a78d1c580388d6c4f14674733";
  96. var openid = "";
  97. uni.request({
  98. url: serverUrl+"/TWeixin/getOpenid?code="+code,
  99. mothod: "GET",
  100. success: (userResult) => {
  101. openid = userResult.data.data;
  102. var parm = {
  103. avatarUrl: "",
  104. nickName: "",
  105. openId: ""
  106. };
  107. parm['avatarUrl'] = userInfo.avatarUrl;
  108. parm['nickName'] = userInfo.nickName;
  109. parm['openId'] = openid;
  110. uni.setStorageSync("newparm", parm);
  111. this.loginweixin();
  112. }
  113. });
  114. }
  115. });
  116. },
  117. loginweixin() {
  118. var parm = uni.getStorageSync("newparm");
  119. if (parm.openId != null) {
  120. this.$store.dispatch('loginWX', parm)
  121. .then(data => {
  122. var result = data.message;
  123. var userInfo = data.data;
  124. if (result == "off") {
  125. uni.setStorageSync("weixinInfo", userInfo);
  126. //没有绑定,跳转到微信绑定页面
  127. uni.reLaunch({
  128. url: "loginWeixin",
  129. });
  130. };
  131. if (result == "SUCCESS") {
  132. // uni.setStorageSync("weixinInfo", weixinInfo);
  133. uni.setStorageSync('test', '1');
  134. uni.reLaunch({
  135. url: '/pages/Charts/mainStatistics',
  136. });
  137. uni.setStorageSync("globalUser", userInfo);
  138. }
  139. });
  140. }
  141. },
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. page {
  147. padding: 200upx 0 0 0;
  148. background-image: url('~@/static/backgrounds/login_bg.png');
  149. background-repeat: no-repeat;
  150. background-size: 100% 100%;
  151. position: absolute;
  152. top: 0;
  153. left: 0;
  154. right: 0;
  155. bottom: 0;
  156. .content {
  157. padding: 0 20upx;
  158. display: flex;
  159. flex-flow: column nowrap;
  160. align-items: center;
  161. .logo {
  162. width: 401upx;
  163. height: 125upx;
  164. text-align: center;
  165. margin: 50upx;
  166. }
  167. form {
  168. width: calc(100% - 100upx);
  169. padding: 50upx;
  170. .section {
  171. margin: 50upx 0;
  172. }
  173. .btn-area {
  174. margin-top: 100upx;
  175. button {
  176. background-color: $uni-color-primary;
  177. }
  178. }
  179. }
  180. }
  181. }
  182. /* 第三方登录 start */
  183. .third-wapper {
  184. width: 100%;
  185. /* 固定底部 */
  186. /* bottom: 0;
  187. position: fixed; */
  188. margin-top: 60upx;
  189. }
  190. .third-line {
  191. display: flex;
  192. flex-direction: row;
  193. justify-content: center
  194. }
  195. .third-words {
  196. color: #A9A9A9;
  197. font-size: 13px;
  198. display: flex;
  199. flex-direction: column;
  200. justify-content: center;
  201. }
  202. .single-line {
  203. padding: 15upx 20upx;
  204. width: 25%;
  205. align-items: center;
  206. }
  207. .third-icos-wapper {
  208. margin-top: 30upx;
  209. display: flex;
  210. flex-direction: row;
  211. justify-content: center
  212. }
  213. .third-ico {
  214. width: 60upx;
  215. height: 60upx;
  216. }
  217. .third-btn-ico {
  218. // background-image:url(http://122.152.205.72:88/group1/M00/00/05/CpoxxFxFO-yAOjTaAAATCIZEzRU503.png);
  219. background-image: url('~@/static/backgrounds/weixin.png');
  220. width: 120upx;
  221. height: 120upx;
  222. background-color: white;
  223. background-size: 120upx 120upx;
  224. // background-repeat:no-repeat;
  225. border: none;
  226. padding: 0;
  227. }
  228. button::after {
  229. border: none;
  230. }
  231. /* 第三方登录 end */
  232. </style>