login.vue 9.1 KB

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