login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. console.log(this.isHistory,'this.isHistory');
  105. if(!this.isHistory){
  106. uni.removeStorageSync("username");
  107. uni.removeStorageSync("password");
  108. }
  109. },
  110. methods: {
  111. checkboxChange(e) {
  112. this.isHistory = e.length > 0 ? true : false
  113. if(e.length<1 ){
  114. uni.removeStorageSync("username");
  115. uni.removeStorageSync("password");
  116. }
  117. console.log(this.isHistory, 'isHistory', e);
  118. },
  119. // 隐私协议
  120. handlePrivacy() {
  121. let site = this.globalConfig.appInfo.agreements[0];
  122. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  123. },
  124. // 用户协议
  125. handleUserAgrement() {
  126. let site = this.globalConfig.appInfo.agreements[1];
  127. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  128. },
  129. // 微信登录模块
  130. //老版登录接口(不再弹出登录弹框)
  131. bindGetUserInfo(e) {
  132. if (e.detail.userInfo) {
  133. //业务逻辑
  134. }
  135. },
  136. signUser() {
  137. uni.navigateTo({
  138. url: '/pages/sign/sign'
  139. })
  140. },
  141. handleClick(n) {
  142. console.log(this.radiovalue1, 'ssssss');
  143. },
  144. // 弹出登录弹框(新版)
  145. getUserProfiles() {
  146. // #ifdef H5
  147. const redirect_uri = 'http://api-security.byants.com/admin-api/system/auth/social-login';
  148. // const state = Math.floor(Math.random() * (10)) + 1
  149. const state = new Date().getTime()
  150. const href_uri =
  151. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7f523d8c12d25542&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=${state}#wechat_redirect`
  152. console.log('href_uri=', href_uri);
  153. location.href = href_uri
  154. // #endif
  155. // #ifdef MP-WEIXIN
  156. if (this.radiovalue1[0] != 1) {
  157. this.$modal.msg('请阅读并勾选用户协议')
  158. return
  159. }
  160. const that = this
  161. //推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息 均需用户确认
  162. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  163. // uni.getUserProfile({
  164. // desc: '用于完善您的个人信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  165. // success: res => {
  166. // //业务逻辑
  167. // this.userInfo = res.userInfo;
  168. // uni.setStorageSync('userInfo', this.userInfo);
  169. // // console.log(res, '成功获取个人信息');
  170. // 发起微信登录请求
  171. uni.login({
  172. provider: 'weixin',
  173. onlyAuthorize: true, // 微信登录仅请求授权认证
  174. success: function(res) {
  175. const {
  176. code
  177. } = res;
  178. console.log(res);
  179. //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
  180. uni.request({
  181. // url: 'http://api-security.byants.com/admin-api/system/user/register',
  182. url: 'http://api-security.byants.com/admin-api/system/auth/social-login',
  183. method: 'POST',
  184. // header: {
  185. // 'content-type': 'application/x-www-form-urlencoded'
  186. // },
  187. data: {
  188. type: 34,
  189. code: res.code,
  190. state: '9b2ffbc1-7425-4155-9894-9d5c08541d62'
  191. // socialType: 34,
  192. // socialState: '9b2ffbc1-7425-4155-9894-9d5c08541d62'
  193. },
  194. success: reponse => {
  195. if (reponse.data.code == 1002000005) {
  196. that.$modal.msg(reponse.data.msg)
  197. setTimeout(() => {
  198. uni.navigateTo({
  199. url: `/pages/bind/bind?socialCode=${res.code}`
  200. })
  201. }, 1000)
  202. } else {
  203. console.log('111111111111', reponse.data.data);
  204. setToken(reponse.data.data)
  205. setUserId(reponse.data.data)
  206. that.loginSuccess();
  207. }
  208. console.log(reponse, '成功调用登录接口');
  209. //获得token完成登录
  210. // uni.setStorageSync('token', res.token);
  211. },
  212. fail: response => {
  213. console.log(response, '未能成功调用登录接口');
  214. }
  215. });
  216. },
  217. fail: function(err) {
  218. console.log(err, '发起uni.login错误错误错误错误错误错误错误');
  219. // 登录授权失败
  220. // err.code是错误码
  221. }
  222. });
  223. // },
  224. // fail: res => {
  225. // uni.showToast({
  226. // title: '你已取消授权',
  227. // icon: 'none',
  228. // duration: 2000
  229. // });
  230. // }
  231. // });
  232. // #endif
  233. },
  234. // 登录方法
  235. async handleLogin(params) {
  236. if (this.loginForm.username === '') {
  237. this.$modal.msgError('请输入您的账号');
  238. } else if (this.loginForm.password === '') {
  239. this.$modal.msgError('请输入您的密码');
  240. } else {
  241. // 显示验证码
  242. // if (this.captchaEnabled) {
  243. // this.$refs.verify.show()
  244. // } else { // 直接登录
  245. await this.pwdLogin({});
  246. // }
  247. }
  248. },
  249. // 密码登录
  250. async pwdLogin(captchaParams) {
  251. this.$modal.loading('登录中,请耐心等待...');
  252. // 执行登录
  253. this.loginForm.captchaVerification = captchaParams.captchaVerification;
  254. this.$store.dispatch('Login', this.loginForm).then(() => {
  255. // uni.setStorageSync('token', res.data.data.token);
  256. this.$modal.closeLoading();
  257. this.loginSuccess();
  258. });
  259. },
  260. // 登录成功后,处理函数
  261. loginSuccess(result) {
  262. if (this.isHistory) {
  263. uni.setStorageSync("username", this.loginForm.username);
  264. uni.setStorageSync("password", this.loginForm.password);
  265. }
  266. this.$store.dispatch('loadDictDatas');
  267. // 设置用户信息
  268. this.$store.dispatch('GetInfo').then(res => {
  269. this.$tab.reLaunch('/pages/index');
  270. // this.$tab.reLaunch('/pages/work/index');
  271. });
  272. }
  273. }
  274. };
  275. </script>
  276. <style lang="scss">
  277. page {
  278. background-color: #ffffff;
  279. }
  280. .normal-login-container {
  281. width: 100%;
  282. .logo-content {
  283. width: 100%;
  284. font-size: 21px;
  285. text-align: center;
  286. image {
  287. border-radius: 4px;
  288. }
  289. .title {
  290. margin-left: 10px;
  291. }
  292. }
  293. .login-form-content {
  294. text-align: left;
  295. margin: 20px auto;
  296. margin-top: 10%;
  297. width: 80%;
  298. .input-item {
  299. margin: 15px auto;
  300. background-color: #f5f9f7;
  301. height: 45px;
  302. border-radius: 20px;
  303. .icon {
  304. font-size: 38rpx;
  305. margin-left: 10px;
  306. color: #999;
  307. }
  308. .input {
  309. width: 100%;
  310. font-size: 14px;
  311. line-height: 20px;
  312. text-align: left;
  313. padding-left: 15px;
  314. }
  315. }
  316. .login-btn {
  317. margin-top: 30px;
  318. height: 90upx;
  319. border-radius: 356upx;
  320. background-color: #4cb2b6;
  321. color: #ffffff;
  322. box-shadow: 0px 2upx 6upx 0px rgba(123, 123, 123, 0.3);
  323. }
  324. .xieyi {
  325. color: #333;
  326. margin-top: 20px;
  327. }
  328. }
  329. .easyinput {
  330. width: 100%;
  331. }
  332. }
  333. // 登录按钮
  334. .login-form-content2 {
  335. text-align: center;
  336. margin: 20px auto;
  337. margin-top: 0%;
  338. width: 75%;
  339. .wx_login {
  340. height: 100upx;
  341. width: 450upx;
  342. // font-size: 16px;
  343. // padding-top: 2px;
  344. // background-color: #f5f7f9;
  345. // color: #728f90;
  346. // border-radius: 356upx;
  347. // box-shadow: 0px 2upx 6upx 0px rgba(123, 123, 123, 0.3);
  348. }
  349. .or {
  350. font-size: 20upx;
  351. margin: 20upx;
  352. color: #98aeaf;
  353. }
  354. }
  355. .login-code-img {
  356. height: 45px;
  357. }
  358. .wx_icon {
  359. position: relative;
  360. margin-top: 27%;
  361. margin-left: 42%;
  362. }
  363. .u-checkbox-group--row {
  364. // justify-content: center;
  365. align-items: center
  366. }
  367. </style>
  368. © 2023 Gogs 当前版本: 0.11.91.0811 页面: 33ms 模板: 0ms 简体中文 官方网站 Go1.12.7