login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="logo-content align-center justify-center flex">
  4. <!-- <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix"></image>
  5. <text style="font-weight: bold;" class="title">宜宾消防公共平台移动端</text> -->
  6. <image :src="login_top" mode="widthFix" class="width100" style="margin-top: -80upx;"></image>
  7. <image :src="description" mode="widthFix" class="img_top"
  8. style="position: absolute;right: 0;top: 120upx; z-index: 999;width: 346upx;height: 330upx;"></image>
  9. </view>
  10. <!-- 账号密码框 -->
  11. <view class="login-form-content">
  12. <text style="color: #98AEAF;">账号</text>
  13. <view class="input-item flex align-center">
  14. <view class="iconfont icon-user icon"></view>
  15. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  16. </view>
  17. <text style="color: #98AEAF;">密码</text>
  18. <view class="input-item flex align-center">
  19. <view class="iconfont icon-password icon"></view>
  20. <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  21. </view>
  22. <view class="">
  23. <u-checkbox-group @change="checkboxChange" activeColor="#4cb2b6">
  24. <u-checkbox type="checkbox" :checked='isHistory' :key="1" :name="1" label="记住密码"></u-checkbox>
  25. </u-checkbox-group>
  26. </view>
  27. <Verify @success="pwdLogin" :mode="'pop'" :captchaType="'blockPuzzle'"
  28. :imgSize="{ width: '330px', height: '155px' }" ref="verify"></Verify>
  29. <!-- 登录按钮 -->
  30. <view class="login-form-content2">
  31. <button @click="handleLogin" class="login-btn cu-btn block lg">登录</button>
  32. <!-- 最新版登录方法 current -->
  33. <!-- #ifdef MP-WEIXIN -->
  34. <view class="or">OR</view>
  35. <view v-on:tap="getUserProfiles">
  36. <img class="wx_login" :src="wx_login" alt="微信登录">
  37. </view>
  38. <!-- #endif -->
  39. <!-- 老版本登录方法 -->
  40. <!-- <button class="wx_login" v-else open-type="getUserInfo" lang="zh_CN" @getuserinfo="bindGetUserInfo">微信登录</button> -->
  41. </view>
  42. <!-- #ifdef MP-WEIXIN -->
  43. <u-checkbox-group v-model="radiovalue1" @change="handleClick" activeColor="#4cb2b6">
  44. <u-checkbox :customStyle="{fontSize:'10px'}">
  45. </u-checkbox>
  46. 登录即代表同意<span style="margin-left: 10rpx;color: #53B7BB;">获取您的用户信息</span>
  47. </u-checkbox-group>
  48. <!-- #endif -->
  49. </view>
  50. <!-- <view class="xieyi text-center">
  51. <text class="text-grey1">登录即代表同意</text>
  52. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  53. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  54. </view> -->
  55. </view>
  56. </template>
  57. <script>
  58. // #ifdef H5
  59. import Verify from '@/pagesA/components/verifition/Verify';
  60. // #endif
  61. import {
  62. setToken,
  63. setUserId,
  64. } from '@/utils/auth'
  65. import config from '@/config'
  66. const baseUrlImg = config.baseUrlImg
  67. export default {
  68. name: 'Login',
  69. components: {
  70. // #ifdef H5
  71. Verify
  72. // #endif
  73. },
  74. data() {
  75. return {
  76. description: `${baseUrlImg}/login/description.png`, //登录页面顶部装饰图
  77. login_top: `${baseUrlImg}/login/login_top.png`, //登录页面顶部
  78. wx_login: `${baseUrlImg}/login/wx_login.png`, //登录按钮
  79. captchaEnabled: true, // 验证码开关 TODO 芋艿:需要抽到配置里
  80. canIUseGetUserProfile: false, // 用来判断用哪个登录
  81. globalConfig: getApp().globalData.config,
  82. userInfo: '',
  83. loginForm: {
  84. // admin123
  85. username: uni.getStorageSync("username")?uni.getStorageSync("username"):'',
  86. password: uni.getStorageSync("password")?uni.getStorageSync("password"):'',
  87. captchaVerification: '',
  88. socialCode: '',
  89. socialType: '',
  90. socialState: '',
  91. },
  92. radiovalue1: [],
  93. isHistory: false,
  94. };
  95. },
  96. onLoad() {
  97. //如果手机支持最新版登录就用新方法
  98. if (uni.getUserProfile) {
  99. this.canIUseGetUserProfile = true;
  100. }
  101. },
  102. onShow(){
  103. this.isHistory=uni.getStorageSync("username")?true:false
  104. if(!this.isHistory){
  105. uni.removeStorageSync("username");
  106. uni.removeStorageSync("password");
  107. }
  108. },
  109. methods: {
  110. checkboxChange(e) {
  111. this.isHistory = e.length > 0 ? true : false
  112. if(e.length<1 ){
  113. uni.removeStorageSync("username");
  114. uni.removeStorageSync("password");
  115. }
  116. },
  117. // 隐私协议
  118. handlePrivacy() {
  119. let site = this.globalConfig.appInfo.agreements[0];
  120. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  121. },
  122. // 用户协议
  123. handleUserAgrement() {
  124. let site = this.globalConfig.appInfo.agreements[1];
  125. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  126. },
  127. // 微信登录模块
  128. //老版登录接口(不再弹出登录弹框)
  129. bindGetUserInfo(e) {
  130. if (e.detail.userInfo) {
  131. //业务逻辑
  132. }
  133. },
  134. signUser() {
  135. uni.navigateTo({
  136. url: '/pages/sign/sign'
  137. })
  138. },
  139. handleClick(n) {
  140. },
  141. // 弹出登录弹框(新版)
  142. getUserProfiles() {
  143. // #ifdef H5
  144. const redirect_uri = 'http://api-security.byants.com/admin-api/system/auth/social-login';
  145. // const state = Math.floor(Math.random() * (10)) + 1
  146. const state = new Date().getTime()
  147. const href_uri =
  148. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7f523d8c12d25542&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=${state}#wechat_redirect`
  149. location.href = href_uri
  150. // #endif
  151. // #ifdef MP-WEIXIN
  152. if (this.radiovalue1[0] != 1) {
  153. this.$modal.msg('请阅读并勾选用户协议')
  154. return
  155. }
  156. const that = this
  157. //推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息 均需用户确认
  158. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  159. // uni.getUserProfile({
  160. // desc: '用于完善您的个人信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  161. // success: res => {
  162. // //业务逻辑
  163. // this.userInfo = res.userInfo;
  164. // uni.setStorageSync('userInfo', this.userInfo);
  165. // // console.log(res, '成功获取个人信息');
  166. // 发起微信登录请求
  167. uni.login({
  168. provider: 'weixin',
  169. onlyAuthorize: true, // 微信登录仅请求授权认证
  170. success: function(res) {
  171. const {
  172. code
  173. } = res;
  174. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  175. uni.request({
  176. // url: 'http://api-security.byants.com/admin-api/system/user/register',
  177. url: 'http://api-security.byants.com/admin-api/system/auth/social-login',
  178. method: 'POST',
  179. // header: {
  180. // 'content-type': 'application/x-www-form-urlencoded'
  181. // },
  182. data: {
  183. type: 34,
  184. code: res.code,
  185. state: '9b2ffbc1-7425-4155-9894-9d5c08541d62'
  186. // socialType: 34,
  187. // socialState: '9b2ffbc1-7425-4155-9894-9d5c08541d62'
  188. },
  189. success: reponse => {
  190. if (reponse.data.code == 1002000005) {
  191. that.$modal.msg(reponse.data.msg)
  192. setTimeout(() => {
  193. uni.navigateTo({
  194. url: `/pages/bind/bind?socialCode=${res.code}`
  195. })
  196. }, 1000)
  197. } else {
  198. setToken(reponse.data.data)
  199. setUserId(reponse.data.data)
  200. that.loginSuccess();
  201. }
  202. //获得token完成登录
  203. // uni.setStorageSync('token', res.token);
  204. },
  205. fail: response => {
  206. }
  207. });
  208. },
  209. fail: function(err) {
  210. // 登录授权失败
  211. // err.code是错误码
  212. }
  213. });
  214. // },
  215. // fail: res => {
  216. // uni.showToast({
  217. // title: '你已取消授权',
  218. // icon: 'none',
  219. // duration: 2000
  220. // });
  221. // }
  222. // });
  223. // #endif
  224. },
  225. // 登录方法
  226. async handleLogin(params) {
  227. if (this.loginForm.username === '') {
  228. this.$modal.msgError('请输入您的账号');
  229. } else if (this.loginForm.password === '') {
  230. this.$modal.msgError('请输入您的密码');
  231. } else {
  232. // 显示验证码
  233. // if (this.captchaEnabled) {
  234. // this.$refs.verify.show()
  235. // } else { // 直接登录
  236. await this.pwdLogin({});
  237. // }
  238. }
  239. },
  240. // 密码登录
  241. async pwdLogin(captchaParams) {
  242. this.$modal.loading('登录中,请耐心等待...');
  243. // 执行登录
  244. this.loginForm.captchaVerification = captchaParams.captchaVerification;
  245. this.$store.dispatch('Login', this.loginForm).then(() => {
  246. // uni.setStorageSync('token', res.data.data.token);
  247. this.$modal.closeLoading();
  248. this.loginSuccess();
  249. });
  250. },
  251. // 登录成功后,处理函数
  252. loginSuccess(result) {
  253. if (this.isHistory) {
  254. uni.setStorageSync("username", this.loginForm.username);
  255. uni.setStorageSync("password", this.loginForm.password);
  256. }
  257. this.$store.dispatch('loadDictDatas');
  258. // 设置用户信息
  259. this.$store.dispatch('GetInfo').then(res => {
  260. this.$tab.reLaunch('/pages/index');
  261. // this.$tab.reLaunch('/pages/work/index');
  262. });
  263. }
  264. }
  265. };
  266. </script>
  267. <style lang="scss">
  268. page {
  269. background-color: #ffffff;
  270. }
  271. .normal-login-container {
  272. width: 100%;
  273. .logo-content {
  274. width: 100%;
  275. font-size: 21px;
  276. text-align: center;
  277. image {
  278. border-radius: 4px;
  279. }
  280. .title {
  281. margin-left: 10px;
  282. }
  283. }
  284. .login-form-content {
  285. text-align: left;
  286. margin: 20px auto;
  287. margin-top: 10%;
  288. width: 80%;
  289. .input-item {
  290. margin: 15px auto;
  291. background-color: #f5f9f7;
  292. height: 45px;
  293. border-radius: 20px;
  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: 30px;
  309. height: 90upx;
  310. border-radius: 356upx;
  311. background-color: #4cb2b6;
  312. color: #ffffff;
  313. box-shadow: 0px 2upx 6upx 0px rgba(123, 123, 123, 0.3);
  314. }
  315. .xieyi {
  316. color: #333;
  317. margin-top: 20px;
  318. }
  319. }
  320. .easyinput {
  321. width: 100%;
  322. }
  323. }
  324. // 登录按钮
  325. .login-form-content2 {
  326. text-align: center;
  327. margin: 20px auto;
  328. margin-top: 0%;
  329. width: 75%;
  330. .wx_login {
  331. height: 100upx;
  332. width: 450upx;
  333. // font-size: 16px;
  334. // padding-top: 2px;
  335. // background-color: #f5f7f9;
  336. // color: #728f90;
  337. // border-radius: 356upx;
  338. // box-shadow: 0px 2upx 6upx 0px rgba(123, 123, 123, 0.3);
  339. }
  340. .or {
  341. font-size: 20upx;
  342. margin: 20upx;
  343. color: #98aeaf;
  344. }
  345. }
  346. .login-code-img {
  347. height: 45px;
  348. }
  349. .wx_icon {
  350. position: relative;
  351. margin-top: 27%;
  352. margin-left: 42%;
  353. }
  354. .u-checkbox-group--row {
  355. // justify-content: center;
  356. align-items: center
  357. }
  358. </style>
  359. © 2023 Gogs 当前版本: 0.11.91.0811 页面: 33ms 模板: 0ms 简体中文 官方网站 Go1.12.7