login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <!-- 登录 -->
  2. <template>
  3. <view id="login">
  4. <!-- <img class="login-max-big" src="@/images/img_bg_dl.png"> -->
  5. <img class="login-max-big" :src="loginBanner">
  6. <view class="login-box">
  7. <view class="tabTitle">
  8. <view class="tabTitle_li" @tap="tabClick(index)" :key="index" v-for="(item,index) in tabText">
  9. <view :class="{on:curTab==index}" class="tabTitle_text">{{item}}</view>
  10. <view :class="{on:curTab==index}" class="tabTitle_across"></view>
  11. </view>
  12. </view>
  13. <view class="input-max-box-one">
  14. <view class="input-box">
  15. <img src="@/images/img_log_in_account.png"/>
  16. <input type="text" v-model="username" placeholder="请输入账号" maxlength="20">
  17. </view>
  18. </view>
  19. <view class="input-max-box-two">
  20. <view class="input-box">
  21. <img src="@/images/img_log_in_password.png"/>
  22. <input type="password" v-model="password" placeholder="请输入密码" maxlength="20">
  23. </view>
  24. </view>
  25. <view class="check-box" @click="checkboxChange">
  26. <img v-if="checkedType" src="@/images/icon_13.png"/>
  27. <img v-if="!checkedType" src="@/images/icon_12.png"/>
  28. <view>记住我</view>
  29. </view>
  30. <view class="button-box" @click="login">登录</view>
  31. <view class="supplier" v-if="curTab==1">
  32. <view class="supplier_l" @click="handleClick('forget')">忘记密码</view>
  33. <view class="supplier_r" @click="handleClick('register')">没有账号,<text>立即注册</text></view>
  34. </view>
  35. </view>
  36. <!-- <img class="top-back" src="@/images/img_sys_bg.png"/> -->
  37. </view>
  38. </template>
  39. <script>
  40. import { config } from '@/api/request/config.js'
  41. import { login,getLogoInfo,getDemoInfoList,getOpenId,getUrlConfig} from '@/api/index.js'
  42. import { Encrypt,Decrypt} from '@/utils/secret.js'
  43. export default {
  44. data() {
  45. return {
  46. identityStatus:1,
  47. username:"",
  48. password:"",
  49. checkedType:false,
  50. loginBanner:uni.getStorageSync('loginBanner'),
  51. infoList:[],//模板消息Id
  52. tabText:['师生登录'],
  53. curTab:0,
  54. }
  55. },
  56. onLoad(option) {
  57. //供应商注册成功后返回到供应商注册页面
  58. if(option.status){
  59. this.identityStatus=2
  60. }
  61. if(uni.getStorageSync('userName') && uni.getStorageSync('password')){
  62. this.username = uni.getStorageSync('userName');
  63. this.password = uni.getStorageSync('password');
  64. this.checkedType = true;
  65. }
  66. },
  67. onShow(){
  68. this.getLogoInfo();
  69. this.getUrlConfig();
  70. },
  71. methods: {
  72. //顶部tab点击
  73. tabClick(index) {
  74. //this.curTab = index;
  75. },
  76. //获取openID
  77. async getOpenId(){
  78. let _this=this;
  79. let code=uni.getStorageSync('code')
  80. const {data} = await getOpenId({code:code});
  81. if(data.code==200){
  82. }else if(data.code==500){
  83. }
  84. },
  85. switchClick(){
  86. if(this.identityStatus==1){
  87. this.identityStatus=2;
  88. }else{
  89. this.identityStatus=1;
  90. }
  91. },
  92. async getLogoInfo(){
  93. const {data} = await getLogoInfo();
  94. if(data.code == 200){
  95. this.loginBanner = config.base_url + data.data.loginBanner;
  96. uni.setStorageSync('loginBanner',config.base_url + data.data.loginBanner)
  97. uni.setStorageSync('homepageBanner',config.base_url + data.data.homepageBanner)
  98. uni.setStorageSync('videoCover',config.base_url + data.data.videoCover)
  99. }
  100. },
  101. async getUrlConfig(){
  102. const {data} = await getUrlConfig();
  103. if(data.code == 200){
  104. //文件预览地址
  105. uni.setStorageSync('filePreviewUrl','https://'+Decrypt(data.data.fileExtranetUrl))
  106. //摄像头代理访问地址
  107. uni.setStorageSync('cameraExtranetAgent','https://'+Decrypt(data.data.cameraExtranetAgent))
  108. //摄像头地址ip段
  109. uni.setStorageSync('cameraIntranetAgent',Decrypt(data.data.cameraIntranetAgent))
  110. //摄像头访问地址
  111. uni.setStorageSync('cameraUrl','https://'+Decrypt(data.data.cameraExtranetUrl))
  112. //MQTT地址
  113. uni.setStorageSync('mqttUrl',Decrypt(data.data.mqttExtranetUrl))
  114. //MQTT账号
  115. uni.setStorageSync('mqttUser',Decrypt(data.data.mqttExtranetUser))
  116. //MQTT密码
  117. uni.setStorageSync('mqttPassword',Decrypt(data.data.mqttExtranetPassword))
  118. }
  119. },
  120. checkboxChange() {
  121. this.checkedType = !this.checkedType;
  122. },
  123. //点击事件
  124. handleClick(doType) {
  125. if(doType=='register'){//供应商注册
  126. uni.redirectTo({
  127. url: '/pages_supplier/register/register?pageStatus=0'
  128. });
  129. }else if(doType=='forget'){//忘记密码
  130. uni.showModal({
  131. showCancel:false,
  132. confirmColor:'#0183FA',
  133. content: '请您联系学校相关管理人员申请重置密码',
  134. success: function (res) {
  135. if (res.confirm) {
  136. }
  137. }
  138. });
  139. }
  140. },
  141. async login() {
  142. let self = this;
  143. let obj = {
  144. username:this.username,
  145. password:this.password,
  146. }
  147. const {data} = await login(obj)
  148. if(data.code == 200){
  149. uni.setStorageSync('token','Bearer '+data.data.access_token);
  150. uni.setStorageSync('userId',data.data.user_id);
  151. this.getOpenId();//获取openid
  152. if(data.data.type == "00" ||data.data.type == "11"){//管理端
  153. uni.setStorageSync('userType',"1");
  154. this.getToken()//订阅消息
  155. }else if(data.data.type == 22){//学生端
  156. uni.setStorageSync('userType',"2");
  157. this.getToken()//订阅消息
  158. }else if(data.data.type == 33){//供应商端
  159. uni.setStorageSync('userType',"3");
  160. this.getToken2()//订阅消息
  161. }
  162. if(this.checkedType){
  163. uni.setStorageSync('userName',this.username)
  164. uni.setStorageSync('password',this.password)
  165. }else{
  166. uni.removeStorageSync('userName')
  167. uni.removeStorageSync('password')
  168. }
  169. if(uni.getStorageSync('saoCode')){
  170. uni.redirectTo({
  171. url: '/pages/saoCode/saoCode'
  172. });
  173. }else if(uni.getStorageSync('mid')){
  174. uni.redirectTo({
  175. url: '/pages_student/mine/codeSuccess'
  176. });
  177. }else if(uni.getStorageSync('saoCodeId')){
  178. uni.redirectTo({
  179. url: '/pages_manage/workbench/laboratory/laboratoryInfo'
  180. });
  181. }else if(uni.getStorageSync('warningId')){//报警信息详情
  182. uni.redirectTo({
  183. url: '/pages/earlyWarningManage/earlyWarningDetail?id='+uni.getStorageSync('warningId')
  184. });
  185. }else{
  186. uni.redirectTo({
  187. url: '/pages/home',
  188. });
  189. }
  190. }
  191. },
  192. //订阅列表查询
  193. async getInfoListId(){
  194. let _this = this;
  195. const {data} = await getDemoInfoList(this.getData)
  196. if(data.code==200){
  197. let _this=this;
  198. let res =data.data
  199. //_this.getToken(res)
  200. }
  201. },
  202. //学生端和管理端订阅消息,出库确认通知,审核结果通知,待审核通知
  203. getToken() {
  204. let _this = this
  205. wx.requestSubscribeMessage({
  206. tmplIds:['Vg6iHUEg6hor7RvP37M7oFCoYGreCu11apJqRB2j37w','0gFoOByDYhCOthJW0tgUi3SHTkLMUK11EfIYlS_qJi4','6yzAPx_o9jn_2xhTt7blDcxjYD1x0vUV1JxUsKqpG4k'],//此处的id替换你要发送订阅的模板id,可在小程序后台新建模板中获取
  207. success(res) {
  208. if(res.errMsg=='requestSubscribeMessage:ok'){
  209. uni.showToast({
  210. title:'订阅成功!',
  211. icon:"none",
  212. mask:true,
  213. duration: 2000
  214. });
  215. }
  216. },
  217. fail: function(res) {
  218. }
  219. })
  220. },
  221. //供应商端订阅消息,待办事项通知
  222. getToken2() {
  223. let _this = this
  224. wx.requestSubscribeMessage({
  225. tmplIds:['2HtEIQ3_PmS0yMd3PHPIIawRqnSP0_He5wrhVKeuqaw'],//此处的id替换你要发送订阅的模板id,可在小程序后台新建模板中获取
  226. success(res) {
  227. if(res.errMsg=='requestSubscribeMessage:ok'){
  228. uni.showToast({
  229. title:'订阅成功!',
  230. icon:"none",
  231. mask:true,
  232. duration: 2000
  233. });
  234. }
  235. },
  236. fail: function(res) {
  237. }
  238. })
  239. }
  240. },
  241. }
  242. </script>
  243. <style lang="stylus" scoped>
  244. #login{
  245. height:100%;
  246. width:100%;
  247. background #f5f5f5
  248. position relative
  249. .login-max-big{
  250. width:750rpx;
  251. height:1177rpx;
  252. z-index:0;
  253. }
  254. .login-box{
  255. z-index:3;
  256. position: absolute
  257. top:446rpx;
  258. left:46rpx;
  259. width:658rpx;
  260. height:700rpx;
  261. // background #fff
  262. /* 切换按钮 */
  263. .tabTitle{
  264. display flex;
  265. width:100%;
  266. height: 100rpx;
  267. position: absolute;
  268. top: 50rpx;
  269. justify-content: center;
  270. >view:nth-of-type(1){
  271. margin-right: 100rpx;
  272. }
  273. .tabTitle_li{
  274. width:168rpx;
  275. text-align center;
  276. .tabTitle_text{
  277. display: inline-block;
  278. font-size: 32rpx;
  279. font-family: PingFang SC;
  280. font-weight: 500;
  281. color: #333333;
  282. line-height: 90rpx;
  283. &.on{
  284. color:#0183FA;
  285. }
  286. }
  287. .tabTitle_across{
  288. width: 100rpx;
  289. height: 4rpx;
  290. background: #0183FA;
  291. border-radius: 2rpx;
  292. margin-left 30rpx;
  293. display none;
  294. &.on{
  295. display block;
  296. }
  297. }
  298. }
  299. }
  300. border-radius:20rpx;
  301. .input-max-box-one{
  302. overflow: hidden;
  303. margin-top:68rpx;
  304. .input-box{
  305. display flex
  306. width:600rpx;
  307. height:80rpx;
  308. border:1rpx solid #e0e0e0;
  309. border-radius:40rpx;
  310. margin:147rpx auto 0;
  311. img{
  312. width:28rpx;
  313. height:32rpx;
  314. margin:24rpx 31rpx;
  315. }
  316. input{
  317. flex:1;
  318. font-size:24rpx;
  319. height:80rpx;
  320. line-height:80rpx;
  321. margin-right:31rpx;
  322. }
  323. }
  324. .text-box{
  325. height:59rpx;
  326. line-height:59rpx;
  327. color:#DC1616;
  328. font-size:24rpx;
  329. margin-left:102rpx;
  330. }
  331. }
  332. .input-max-box-two{
  333. margin-top:40rpx;
  334. .input-box{
  335. display flex
  336. width:600rpx;
  337. height:80rpx;
  338. border:1rpx solid #e0e0e0;
  339. border-radius:40rpx;
  340. margin:0 auto 0;
  341. img{
  342. width:30rpx;
  343. height:32rpx;
  344. margin:24rpx 30rpx;
  345. }
  346. input{
  347. flex:1;
  348. font-size:24rpx;
  349. height:80rpx;
  350. line-height:80rpx;
  351. margin-right:31rpx;
  352. }
  353. }
  354. .text-box{
  355. height:59rpx;
  356. line-height:59rpx;
  357. color:#DC1616;
  358. font-size:24rpx;
  359. margin-left:102rpx;
  360. }
  361. }
  362. .check-box{
  363. margin:30rpx 0 30rpx 104rpx;
  364. width:300rpx;
  365. height:50rpx;
  366. display:flex;
  367. img{
  368. margin-top:10rpx;
  369. width:32rpx;
  370. height:32rpx;
  371. margin-right:10rpx;
  372. }
  373. view{
  374. font-size:24rpx;
  375. line-height:50rpx;
  376. }
  377. }
  378. .button-box{
  379. width: 600rpx;
  380. line-height: 80rpx;
  381. background: #0183FA;
  382. border-radius: 40rpx;
  383. font-size: 36rpx;
  384. color:#fff;
  385. text-align center
  386. margin:0 auto 0;
  387. }
  388. /* 供应商注册 */
  389. .supplier{
  390. display: flex;
  391. justify-content: space-between;
  392. margin:30rpx 40rpx 0;
  393. .supplier_l{
  394. font-size: 24rpx;
  395. font-family: PingFang SC;
  396. font-weight: 400;
  397. color: #333333;
  398. line-height: 24rpx;
  399. }
  400. .supplier_r{
  401. font-size: 24rpx;
  402. font-family: PingFang SC;
  403. font-weight: 400;
  404. color: #333333;
  405. line-height: 24rpx;
  406. >text{
  407. color: #0183FA;
  408. }
  409. }
  410. }
  411. /* 供应商切换 */
  412. .switch_btn{
  413. display: flex;
  414. justify-content: center;
  415. align-items: center;
  416. font-size: 24rpx;
  417. font-family: PingFang SC;
  418. font-weight: 400;
  419. color: #0183FA;
  420. line-height: 24rpx;
  421. margin-top: 60rpx;
  422. >img{
  423. width: 24rpx;
  424. height: 24rpx;
  425. margin-left: 12rpx;
  426. }
  427. }
  428. }
  429. .top-back{
  430. z-index:2;
  431. position: absolute
  432. top:261rpx;
  433. left:375rpx;
  434. height:296rpx;
  435. width:366rpx;
  436. }
  437. }
  438. </style>