login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <view class="normal-login-container" v-if="loginflag">
  3. <image :src="bgimg" class="loginbg"></image>
  4. <view class="loginbox">
  5. <view class="login_top">
  6. <view class="title">登录</view>
  7. <view class="txt">
  8. <!-- <text>招商引资管理系统</text>
  9. / -->
  10. <text>潜山市政府投资重点项目管理系统</text>
  11. </view>
  12. </view>
  13. <view class="login-form-content">
  14. <view class="input-item">
  15. <view class="login_tit">账号名称</view>
  16. <view class="login_box">
  17. <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号名称" maxlength="30" />
  18. </view>
  19. </view>
  20. <view class="input-item" >
  21. <view class="login_tit">登录密码</view>
  22. <view class="login_box">
  23. <input v-if="checkeye" v-model="loginForm.password" type="text" class="input" placeholder="请输入密码" maxlength="20" />
  24. <input v-else v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  25. <view class="input_ye" v-if="loginForm.password" @click="checkeye=!checkeye">
  26. <image :src="yeimgs" v-if="checkeye"></image>
  27. <image :src="yeimg" v-else></image>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="input-item flex align-center" style="width: 60%;margin: 0px;margin-bottom: 24rpx;" v-if="captchaEnabled">
  32. <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  33. <view class="login-code">
  34. <image :src="codeUrl" @click="getCode" class="login-code-img"></image>
  35. </view >
  36. </view>
  37. <view class="flexc login_jz " :class="jzflag?'act':''" @click="jzflag=!jzflag">
  38. <image :src="jzimg" v-if="jzflag"></image>
  39. <image :src="jnzimg" v-else></image>
  40. <view>保存账号及密码</view></view>
  41. <view class="action-btn">
  42. <button @click="handleLogin" class="login-btn cu-btn block lg " :class="loginForm.username&&loginForm.password?'btn2':'btn'">登录</button>
  43. </view>
  44. </view>
  45. <view class="xieyi text-center" >
  46. <image :src="readimg" class="image" v-if="readflag" @click="readflag=!readflag"></image>
  47. <image :src="readimgs" class="image" v-else @click="readflag=!readflag"></image>
  48. <text class="text-grey1">我已阅读并同意</text>
  49. <text @click="handleUserAgrement" class="xieyifa">《用户协议》</text>
  50. <text @click="handlePrivacy" class="xieyifa">《隐私协议》</text>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. const jpushModule = uni.requireNativePlugin('JG-JPush')
  57. import { getCodeImg,getCode,sendSmsOnly } from '@/api/login'
  58. import {getSMS} from '@/utils/common.js'
  59. import { getToken } from '@/utils/auth'
  60. import {updateUserProfile} from "@/api/system/user.js"
  61. export default {
  62. data() {
  63. return {
  64. //极光推送
  65. connectStatus: '未连接',
  66. registrationID: '未获得',
  67. bgimg:require("@/static/images/mine/loginbg.jpg"),
  68. yeimg:require("@/static/images/mine/nyea.png"),
  69. yeimgs:require("@/static/images/mine/yea.png"),
  70. readimg:require("@/static/images/mine/check.png"),
  71. readimgs:require("@/static/images/mine/ncheck.png"),
  72. jzimg:require('@/static/images/mine/jicon.png'),
  73. jnzimg:require('@/static/images/mine/jnicon.png'),
  74. readflag:false,
  75. pwdtype:'password',
  76. codeUrl: "",
  77. captchaEnabled: true,
  78. checkeye:false,
  79. globalConfig: getApp().globalData.config,
  80. type:'',//1 账号密码 2短信
  81. typeflag:1,
  82. time:'',
  83. timefalg:'',
  84. loginflag:false,
  85. loginForm: {
  86. username: "",
  87. code: "",
  88. password:'',
  89. },
  90. jzflag:false
  91. }
  92. },
  93. created() {
  94. // 账号密码登录需要
  95. this.getCode()
  96. },
  97. onLoad() {
  98. // userType:00 系统用户
  99. if (getToken()) {
  100. var userType=this.$store.state.user.userType;
  101. var newArr=userType.split(',')
  102. var num=0,b=0;
  103. for(var i=0;i<newArr.length;i++){
  104. if(newArr[i]=='发改委'){
  105. num=1
  106. break;
  107. }
  108. if(newArr[i]=='招商'){
  109. b=1
  110. break;
  111. }
  112. }
  113. if(num==1){
  114. if(b==1){
  115. this.$tab.reLaunch('/pages/index')
  116. }else{
  117. this.$tab.reLaunch('/pages/indexs')
  118. }
  119. }else{
  120. this.$tab.reLaunch('/pages/index')
  121. }
  122. // uni.switchTab({
  123. // url:'/pages/index'
  124. // })
  125. } else {
  126. this.loginflag=true;
  127. if(uni.getStorageSync('account')){
  128. var newObj=JSON.parse(JSON.stringify(uni.getStorageSync('account')))
  129. this.loginForm.username=newObj.username;
  130. this.loginForm.password=newObj.password;
  131. this.jzflag=true;
  132. this.readflag=true;
  133. // 自动登录
  134. // this.handleLogin()
  135. }
  136. }
  137. },
  138. onUnload() {
  139. },
  140. methods: {
  141. //点击登录按钮
  142. login() {
  143. //登录成功后
  144. //设置别名
  145. // jpushModule.setAlias({
  146. // 'alias': this.phone,
  147. // 'sequence': 1
  148. // })
  149. },
  150. connect() {
  151. this.getRegistrationID()
  152. // uni.$on('connectStatusChange', (connectStatus) => {
  153. // console.log('进入连接')
  154. // var connectStr = ''
  155. // if (connectStatus == true) {
  156. // connectStr = '已连接'
  157. // this.getRegistrationID()
  158. // } else {
  159. // connectStr = '未连接'
  160. // }
  161. // console.log('监听到了连接状态变化 --- ', connectStr)
  162. // this.connectStatus = connectStr
  163. // })
  164. },
  165. //获取推送ID
  166. getRegistrationID() {
  167. jpushModule.getRegistrationID(result => {
  168. let registerID = result.registerID
  169. // console.log(result,7)
  170. var params={
  171. jgId:registerID,
  172. }
  173. updateUserProfile(params).then(res=>{
  174. if(rtes.code==200){
  175. console.log(res,9)
  176. }
  177. })
  178. })
  179. },
  180. // 隐私协议
  181. handlePrivacy() {
  182. this.$tab.navigateTo('/pages/agreement')
  183. },
  184. // 用户协议
  185. handleUserAgrement() {
  186. this.$tab.navigateTo('/pages/agreement')
  187. },
  188. // 获取图形验证码
  189. getCode() {
  190. getCodeImg().then(res => {
  191. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  192. if (this.captchaEnabled) {
  193. this.codeUrl = 'data:image/gif;base64,' + res.img
  194. this.loginForm.uuid = res.uuid
  195. }
  196. })
  197. },
  198. // 登录方法
  199. async handleLogin() {
  200. var that=this;
  201. setTimeout(function(){
  202. if(!that.loginForm.username||!that.loginForm.password){
  203. return
  204. }
  205. if(that.readflag){
  206. // 判断是否记住密码
  207. if(that.jzflag){
  208. var newObj={
  209. username:that.loginForm.username,
  210. password:that.loginForm.password,
  211. captchaEnabled:that.captchaEnabled,
  212. }
  213. uni.setStorageSync('account', JSON.parse(JSON.stringify(newObj)))
  214. }else{
  215. uni.removeStorageSync('account')
  216. }
  217. that.$toast("登录中,请耐心等待...")
  218. that.pwdLogin()
  219. }else{
  220. that.$toast("请同意用户协议")
  221. }
  222. },200)
  223. },
  224. // 密码登录
  225. async pwdLogin() {
  226. var that=this;
  227. this.$store.dispatch('Login', this.loginForm).then((res) => {
  228. this.$modal.closeLoading()
  229. this.$toast('登录成功')
  230. setTimeout(function(){
  231. // #ifdef APP-PLUS
  232. // that.getRegistrationID();
  233. // #endif
  234. that.loginSuccess()
  235. },1500)
  236. }).catch((error) => {
  237. setTimeout(function(){
  238. if (that.captchaEnabled) {
  239. that.getCode()
  240. }
  241. },1000)
  242. })
  243. },
  244. // 登录成功后,处理函数
  245. loginSuccess(result) {
  246. // 设置用户信息
  247. var that=this;
  248. this.$store.dispatch('GetInfo').then(res => {
  249. var userType=res.user.userType;
  250. var newArr=userType.split(',')
  251. var num=0,b=0;
  252. for(var i=0;i<newArr.length;i++){
  253. if(newArr[i]=='发改委'){
  254. num=1
  255. break;
  256. }
  257. if(newArr[i]=='招商'){
  258. b=1
  259. break;
  260. }
  261. }
  262. if(num==1){
  263. if(b==1){
  264. this.$tab.reLaunch('/pages/index')
  265. }else{
  266. this.$tab.reLaunch('/pages/indexs')
  267. }
  268. }else{
  269. this.$tab.reLaunch('/pages/index')
  270. }
  271. })
  272. }
  273. }
  274. }
  275. </script>
  276. <style lang="scss">
  277. page {
  278. background-color: #ffffff;
  279. width: 100%;height: 100vh;
  280. }
  281. .loginbg{width: 100%;height:100vh;display: block;}
  282. .loginbox{padding: 0rpx 64rpx 52rpx;width: 100%;box-sizing: border-box;overflow: auto;top: -100rpx;position: fixed;left: 0;right: 0;top: 0;bottom: 0;padding-top: 200rpx;}
  283. .normal-login-container {
  284. width: 100%;
  285. height: 100vh;
  286. position: relative;
  287. .logo-content {
  288. width: 100%;
  289. font-size: 44rpx;
  290. text-align: center;
  291. image {
  292. border-radius: 4px;
  293. }
  294. .title {font-size: 52rpx;color: #343434;;font-weight: bold;}
  295. }
  296. .login-form-content {
  297. margin: 0 auto;
  298. margin-top: 80rpx;
  299. width: 100%;
  300. .input-item {
  301. // margin-bottom:48rpx;
  302. border-bottom: 2rpx solid #CDCDCD;
  303. padding: 40rpx 0 0rpx;
  304. .icon {
  305. font-size: 40rpx;
  306. margin-left: 10px;
  307. color: #999;
  308. }
  309. .login_tit{
  310. font-size: 34rpx;
  311. font-weight: bold;
  312. color: #343434;margin-bottom: 20rpx;
  313. }
  314. .login_box{display: flex;align-items: center;}
  315. .input {
  316. width: 100%;
  317. font-size: 32rpx;
  318. height: 80rpx;
  319. line-height: 80rpx;
  320. }
  321. }
  322. .login-btn {
  323. margin-top: 52rpx;
  324. width: 100%;
  325. height: 80rpx;
  326. border-radius: 6rpx;
  327. margin-bottom: 28rpx;
  328. &.btn{background: #9a9c9e;color: #ffffff;}
  329. &.btn1{border: 2rpx solid #1678FF;color: #1678FF;background-color: #ffffff;margin-top: 0;}
  330. &.btn2{background: $uni-color-fa;color: #ffffff;}
  331. }
  332. .login-code {
  333. height: 38px;
  334. float: right;
  335. .login-code-img {
  336. height: 38px;
  337. position: absolute;
  338. margin-left: 10px;
  339. width: 200rpx;
  340. }
  341. }
  342. }
  343. }
  344. .login_jz{display: flex;align-items: center;justify-content: flex-end;margin-top: 32rpx;
  345. image{width: 32rpx;height: 32rpx;margin-right: 12rpx;}
  346. view{color: #666666;}
  347. &.act{
  348. view{color: #28C529;}
  349. }
  350. }
  351. .xieyi {
  352. color: #333;
  353. margin-top: 26px;
  354. font-size: 26rpx;
  355. display: flex;align-items: center;justify-content: center;
  356. .xieyifa{ color: $uni-color-fa;}
  357. }
  358. .image{width: 32rpx;height: 32rpx;margin-right: 14rpx;}
  359. .input_ye image{width: 36rpx;height: 20rpx;}
  360. .codess{font-size: 34rpx;color: #1678FF;flex: 0 0 auto;min-width: 200rpx;text-align: center;border-left: 2rpx solid #CDCDCD;}
  361. .codes{background: none;font-size: 28rpx;flex: 0 0 auto;width: 180rpx;text-align: center;border-left: 2rpx solid #CDCDCD;}
  362. .login_box{display: flex;align-items: center;}
  363. .login_boxl{width:130rpx;font-size: 34rpx;color: #343434;border-right: 2rpx solid #CDCDCD;}
  364. .login_top{
  365. .title{font-size: 52rpx;color: #343434;;font-weight: bold;position: relative;
  366. &::after{content: '';width: 42rpx;height: 4rpx;background: $uni-color-fa;position: absolute;bottom: -23rpx;left: 0;}
  367. }
  368. .txt{font-size: 32rpx;font-weight: 500;color: #666666;margin-top: 50rpx;
  369. text{display: inline-block;padding: 0 10rpx}
  370. }
  371. }
  372. </style>