login.vue 9.2 KB

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