login.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <!-- @format -->
  2. <template>
  3. <view class="normal-login-container">
  4. <view class="logo-content align-center justify-center flex">
  5. <text class="title" style="margin-top: 100rpx">河北省计量业务应用平台</text>
  6. </view>
  7. <view class="tabs justify-center" style="padding-bottom: 10rpx; margin-top: 100rpx">
  8. <u-tabs :itemStyle="{ width: '250rpx', marginBottom: '20rpx' }" :lineWidth="60" :lineHeight="3"
  9. :inactiveStyle="{ fontSize: '34rpx', color: 'black' }"
  10. :activeStyle="{ color: '#3c9cff', fontSize: '34rpx' }" :list="tabsList"
  11. @click="handleChangeTabs"></u-tabs>
  12. </view>
  13. <view class="login-form-content">
  14. <view class="" v-if="activeTab == '用户名登录'">
  15. <view class="input-item flex align-center">
  16. <view class="iconfont icon-user icon"></view>
  17. <input v-model="loginForm.username" class="input" type="text" placeholder="用户名" maxlength="30" />
  18. </view>
  19. <view class="input-item flex align-center">
  20. <view class="iconfont icon-password icon"></view>
  21. <input v-model="loginForm.password" type="password" class="input" placeholder="密码" maxlength="20" />
  22. </view>
  23. </view>
  24. <view class="" v-else>
  25. <view class="input-item flex align-center">
  26. <u-icon class="iconfont icon" name="phone-fill" size="19"></u-icon>
  27. <input v-model="loginForm.username" class="input" type="text" placeholder="手机号" maxlength="30" />
  28. </view>
  29. <view class="input-item flex align-center">
  30. <u-icon class="iconfont icon" name="chat" size="19"></u-icon>
  31. <input v-model="loginForm.password" type="password" class="input" placeholder="验证码"
  32. maxlength="20" />
  33. </view>
  34. </view>
  35. <view class="action-btn">
  36. <u-button @click="handleLogin" class="login-btn" style="font-size: 17px" type="primary"
  37. shape="circle">登录
  38. </u-button>
  39. </view>
  40. <view class="enroll">
  41. <view @click="handlePersonRegistered">个人注册</view>
  42. <view @click="handleCompaniesRegistration">企业注册</view>
  43. </view>
  44. <view style="margin-top: 60rpx">
  45. <u-divider text="微信登录" :hairline="true"></u-divider>
  46. <view>
  47. <uni-icons @click="showModal = true" type="weixin" size="35"></uni-icons>
  48. </view>
  49. </view>
  50. <!-- <view class="reg text-center" v-if="register">
  51. <text class="text-grey1">没有账号?</text>
  52. <text @click="handleUserRegister" class="text-blue">立即注册</text>
  53. </view> -->
  54. <!-- <view class="xieyi text-center">
  55. <text class="text-grey1">登录即代表同意</text>
  56. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  57. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  58. </view> -->
  59. </view>
  60. <u-modal showCancelButton cancelText="取消" @cancel="showModal = false" @close="showModal = false"
  61. confirmText="确认" @confirm="handleWeixinLogin" :show="showModal" :title="'提示'" :content="content"></u-modal>
  62. </view>
  63. </template>
  64. <script>
  65. import {
  66. wxLogin
  67. } from "@/api/login";
  68. export default {
  69. data() {
  70. return {
  71. content: "使用当前微信登录,如果微信没有绑定用户需要先去绑定。",
  72. showModal: false,
  73. activeTab: "",
  74. tabsList: [{
  75. name: "用户登录",
  76. },
  77. // {
  78. // name: "手机号登录",
  79. // },
  80. ],
  81. codeUrl: "",
  82. captchaEnabled: true,
  83. // 用户注册开关
  84. register: false,
  85. globalConfig: getApp().globalData.config,
  86. loginForm: {
  87. username: "999901234567890HPG",
  88. password: "hpg123789",
  89. code: "",
  90. uuid: "",
  91. },
  92. };
  93. },
  94. created() {},
  95. methods: {
  96. //微信授权登录
  97. handleWeixinLogin() {
  98. uni.getProvider({
  99. service: "oauth",
  100. success: (res) => {
  101. if (~res.provider.indexOf("weixin")) {
  102. uni.login({
  103. provider: "weixin",
  104. success: (loginRes) => {
  105. wxLogin({
  106. code: loginRes.code,
  107. }).then(({
  108. data
  109. }) => {
  110. uni.setStorageSync("unionId", data.unionId);
  111. if (!data.token) {
  112. uni.navigateTo({
  113. url: `/pages/bindweixin?openid=${data.openid}&unionId=${data.unionId}`,
  114. success: (res) => {},
  115. fail: () => {},
  116. complete: () => {},
  117. });
  118. } else {
  119. this.$store
  120. .dispatch("weixinLogin", data.token)
  121. .then((res) => {
  122. this.loginSuccess();
  123. });
  124. }
  125. });
  126. },
  127. });
  128. }
  129. },
  130. });
  131. },
  132. //个人注册
  133. handlePersonRegistered() {
  134. this.$tab.navigateTo(
  135. `/pages/personRegistered/index`
  136. );
  137. // uni.navigateTo({
  138. // url: "/pages/personRegistered/index",
  139. // success: (res) => {},
  140. // fail: () => {},
  141. // complete: () => {},
  142. // });
  143. },
  144. //企业注册
  145. handleCompaniesRegistration() {
  146. uni.navigateTo({
  147. url: "/pages/companiesRegistered/companiesNotify",
  148. });
  149. },
  150. //tabs切换
  151. handleChangeTabs(row) {
  152. this.activeTab = row.name;
  153. },
  154. // 用户注册
  155. handleUserRegister() {
  156. this.$tab.redirectTo(`/pages/register`);
  157. },
  158. // 隐私协议
  159. handlePrivacy() {
  160. let site = this.globalConfig.appInfo.agreements[0];
  161. this.$tab.navigateTo(
  162. `/pages/common/webview/index?title=${site.title}&url=${site.url}`
  163. );
  164. },
  165. // 用户协议
  166. handleUserAgrement() {
  167. let site = this.globalConfig.appInfo.agreements[1];
  168. this.$tab.navigateTo(
  169. `/pages/common/webview/index?title=${site.title}&url=${site.url}`
  170. );
  171. },
  172. // 登录方法
  173. async handleLogin() {
  174. if (this.loginForm.username === "") {
  175. this.$modal.msgError("请输入您的账号");
  176. } else if (this.loginForm.password === "") {
  177. this.$modal.msgError("请输入您的密码");
  178. } else {
  179. this.$modal.loading("登录中,请耐心等待...");
  180. this.pwdLogin();
  181. }
  182. },
  183. // 密码登录
  184. async pwdLogin() {
  185. this.$store
  186. .dispatch("Login", this.loginForm)
  187. .then(() => {
  188. this.$modal.closeLoading();
  189. this.loginSuccess();
  190. })
  191. .catch(() => {});
  192. },
  193. // 登录成功后,处理函数
  194. loginSuccess(result) {
  195. // 设置用户信息
  196. this.$store.dispatch("GetInfo").then((res) => {
  197. this.$tab.reLaunch("/pages/index");
  198. });
  199. },
  200. },
  201. };
  202. </script>
  203. <style lang="scss">
  204. page {
  205. background-color: #ffffff;
  206. }
  207. .enroll {
  208. display: flex;
  209. justify-content: space-between;
  210. margin-top: 50rpx;
  211. color: #3c9cff;
  212. font-size: 30rpx;
  213. font-weight: bold;
  214. }
  215. .normal-login-container {
  216. height: 100vh;
  217. width: 100%;
  218. background-image: url("../static/images/loginBg.png");
  219. background-size: cover;
  220. .logo-content {
  221. width: 100%;
  222. font-size: 21px;
  223. text-align: center;
  224. padding-top: 25%;
  225. image {
  226. border-radius: 4px;
  227. }
  228. .title {
  229. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  230. "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
  231. "Helvetica Neue", sans-serif;
  232. font-weight: bold;
  233. margin-left: 10px;
  234. font-size: 50rpx;
  235. }
  236. }
  237. .login-form-content {
  238. text-align: center;
  239. margin: 40rpx auto;
  240. width: 80%;
  241. .input-item {
  242. margin: 20px auto;
  243. background-color: #f5f6f7;
  244. height: 45px;
  245. border-radius: 10px;
  246. .icon {
  247. font-size: 38rpx;
  248. margin-left: 10px;
  249. color: #999;
  250. }
  251. .input {
  252. width: 100%;
  253. font-size: 14px;
  254. line-height: 20px;
  255. text-align: left;
  256. padding-left: 15px;
  257. }
  258. }
  259. .login-btn {
  260. margin-top: 40px;
  261. height: 45px;
  262. }
  263. .reg {
  264. margin-top: 15px;
  265. }
  266. .xieyi {
  267. color: #333;
  268. margin-top: 20px;
  269. }
  270. .login-code {
  271. height: 38px;
  272. float: right;
  273. .login-code-img {
  274. height: 38px;
  275. position: absolute;
  276. margin-left: 10px;
  277. width: 200rpx;
  278. }
  279. }
  280. }
  281. }
  282. .tabs {
  283. display: flex;
  284. margin: 40rpx auto;
  285. }
  286. </style>