login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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://'+data.data.fileExtranetUrl)
  106. //摄像头代理访问地址
  107. uni.setStorageSync('cameraExtranetAgent','https://'+data.data.cameraExtranetAgent)
  108. //摄像头地址ip段
  109. uni.setStorageSync('cameraIntranetAgent',data.data.cameraIntranetAgent)
  110. //摄像头访问地址
  111. uni.setStorageSync('cameraUrl','https://'+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. tenantId:uni.getStorageSync('tenantId'),//0 系统 1化学与材料学院 2环境气候研究院
  152. this.getOpenId();//获取openid
  153. if(data.data.type == "00" ||data.data.type == "11"){//管理端
  154. uni.setStorageSync('userType',"1");
  155. this.getToken()//订阅消息
  156. }else if(data.data.type == 22){//学生端
  157. uni.setStorageSync('userType',"2");
  158. this.getToken()//订阅消息
  159. }else if(data.data.type == 33){//供应商端
  160. uni.setStorageSync('userType',"3");
  161. this.getToken2()//订阅消息
  162. }
  163. if(this.checkedType){
  164. uni.setStorageSync('userName',this.username)
  165. uni.setStorageSync('password',this.password)
  166. }else{
  167. uni.removeStorageSync('userName')
  168. uni.removeStorageSync('password')
  169. }
  170. if(uni.getStorageSync('saoCode')){
  171. uni.redirectTo({
  172. url: '/pages/saoCode/saoCode'
  173. });
  174. }else if(uni.getStorageSync('mid')){
  175. uni.redirectTo({
  176. url: '/pages_student/mine/codeSuccess'
  177. });
  178. }else if(uni.getStorageSync('saoCodeId')){
  179. uni.redirectTo({
  180. url: '/pages_manage/workbench/laboratory/laboratoryInfo'
  181. });
  182. }else if(uni.getStorageSync('warningId')){//报警信息详情
  183. uni.redirectTo({
  184. url: '/pages/earlyWarningManage/earlyWarningDetail?id='+uni.getStorageSync('warningId')
  185. });
  186. }else{
  187. uni.redirectTo({
  188. url: '/pages/home',
  189. });
  190. }
  191. }
  192. },
  193. //订阅列表查询
  194. async getInfoListId(){
  195. let _this = this;
  196. const {data} = await getDemoInfoList(this.getData)
  197. if(data.code==200){
  198. let _this=this;
  199. let res =data.data
  200. //_this.getToken(res)
  201. }
  202. },
  203. //学生端和管理端订阅消息,出库确认通知,审核结果通知,待审核通知
  204. getToken() {
  205. let _this = this
  206. wx.requestSubscribeMessage({
  207. tmplIds:['Vg6iHUEg6hor7RvP37M7oFCoYGreCu11apJqRB2j37w','0gFoOByDYhCOthJW0tgUi3SHTkLMUK11EfIYlS_qJi4','6yzAPx_o9jn_2xhTt7blDcxjYD1x0vUV1JxUsKqpG4k'],//此处的id替换你要发送订阅的模板id,可在小程序后台新建模板中获取
  208. success(res) {
  209. if(res.errMsg=='requestSubscribeMessage:ok'){
  210. uni.showToast({
  211. title:'订阅成功!',
  212. icon:"none",
  213. mask:true,
  214. duration: 2000
  215. });
  216. }
  217. },
  218. fail: function(res) {
  219. }
  220. })
  221. },
  222. //供应商端订阅消息,待办事项通知
  223. getToken2() {
  224. let _this = this
  225. wx.requestSubscribeMessage({
  226. tmplIds:['2HtEIQ3_PmS0yMd3PHPIIawRqnSP0_He5wrhVKeuqaw'],//此处的id替换你要发送订阅的模板id,可在小程序后台新建模板中获取
  227. success(res) {
  228. if(res.errMsg=='requestSubscribeMessage:ok'){
  229. uni.showToast({
  230. title:'订阅成功!',
  231. icon:"none",
  232. mask:true,
  233. duration: 2000
  234. });
  235. }
  236. },
  237. fail: function(res) {
  238. }
  239. })
  240. }
  241. },
  242. }
  243. </script>
  244. <style lang="stylus" scoped>
  245. #login{
  246. height:100%;
  247. width:100%;
  248. background #f5f5f5
  249. position relative
  250. .login-max-big{
  251. width:750rpx;
  252. height:1177rpx;
  253. z-index:0;
  254. }
  255. .login-box{
  256. z-index:3;
  257. position: absolute
  258. top:446rpx;
  259. left:46rpx;
  260. width:658rpx;
  261. height:700rpx;
  262. // background #fff
  263. /* 切换按钮 */
  264. .tabTitle{
  265. display flex;
  266. width:100%;
  267. height: 100rpx;
  268. position: absolute;
  269. top: 50rpx;
  270. justify-content: center;
  271. >view:nth-of-type(1){
  272. margin-right: 100rpx;
  273. }
  274. .tabTitle_li{
  275. width:168rpx;
  276. text-align center;
  277. .tabTitle_text{
  278. display: inline-block;
  279. font-size: 32rpx;
  280. font-family: PingFang SC;
  281. font-weight: 500;
  282. color: #333333;
  283. line-height: 90rpx;
  284. &.on{
  285. color:#0183FA;
  286. }
  287. }
  288. .tabTitle_across{
  289. width: 100rpx;
  290. height: 4rpx;
  291. background: #0183FA;
  292. border-radius: 2rpx;
  293. margin-left 30rpx;
  294. display none;
  295. &.on{
  296. display block;
  297. }
  298. }
  299. }
  300. }
  301. border-radius:20rpx;
  302. .input-max-box-one{
  303. overflow: hidden;
  304. margin-top:68rpx;
  305. .input-box{
  306. display flex
  307. width:600rpx;
  308. height:80rpx;
  309. border:1rpx solid #e0e0e0;
  310. border-radius:40rpx;
  311. margin:147rpx auto 0;
  312. img{
  313. width:28rpx;
  314. height:32rpx;
  315. margin:24rpx 31rpx;
  316. }
  317. input{
  318. flex:1;
  319. font-size:24rpx;
  320. height:80rpx;
  321. line-height:80rpx;
  322. margin-right:31rpx;
  323. }
  324. }
  325. .text-box{
  326. height:59rpx;
  327. line-height:59rpx;
  328. color:#DC1616;
  329. font-size:24rpx;
  330. margin-left:102rpx;
  331. }
  332. }
  333. .input-max-box-two{
  334. margin-top:40rpx;
  335. .input-box{
  336. display flex
  337. width:600rpx;
  338. height:80rpx;
  339. border:1rpx solid #e0e0e0;
  340. border-radius:40rpx;
  341. margin:0 auto 0;
  342. img{
  343. width:30rpx;
  344. height:32rpx;
  345. margin:24rpx 30rpx;
  346. }
  347. input{
  348. flex:1;
  349. font-size:24rpx;
  350. height:80rpx;
  351. line-height:80rpx;
  352. margin-right:31rpx;
  353. }
  354. }
  355. .text-box{
  356. height:59rpx;
  357. line-height:59rpx;
  358. color:#DC1616;
  359. font-size:24rpx;
  360. margin-left:102rpx;
  361. }
  362. }
  363. .check-box{
  364. margin:30rpx 0 30rpx 104rpx;
  365. width:300rpx;
  366. height:50rpx;
  367. display:flex;
  368. img{
  369. margin-top:10rpx;
  370. width:32rpx;
  371. height:32rpx;
  372. margin-right:10rpx;
  373. }
  374. view{
  375. font-size:24rpx;
  376. line-height:50rpx;
  377. }
  378. }
  379. .button-box{
  380. width: 600rpx;
  381. line-height: 80rpx;
  382. background: #0183FA;
  383. border-radius: 40rpx;
  384. font-size: 36rpx;
  385. color:#fff;
  386. text-align center
  387. margin:0 auto 0;
  388. }
  389. /* 供应商注册 */
  390. .supplier{
  391. display: flex;
  392. justify-content: space-between;
  393. margin:30rpx 40rpx 0;
  394. .supplier_l{
  395. font-size: 24rpx;
  396. font-family: PingFang SC;
  397. font-weight: 400;
  398. color: #333333;
  399. line-height: 24rpx;
  400. }
  401. .supplier_r{
  402. font-size: 24rpx;
  403. font-family: PingFang SC;
  404. font-weight: 400;
  405. color: #333333;
  406. line-height: 24rpx;
  407. >text{
  408. color: #0183FA;
  409. }
  410. }
  411. }
  412. /* 供应商切换 */
  413. .switch_btn{
  414. display: flex;
  415. justify-content: center;
  416. align-items: center;
  417. font-size: 24rpx;
  418. font-family: PingFang SC;
  419. font-weight: 400;
  420. color: #0183FA;
  421. line-height: 24rpx;
  422. margin-top: 60rpx;
  423. >img{
  424. width: 24rpx;
  425. height: 24rpx;
  426. margin-left: 12rpx;
  427. }
  428. }
  429. }
  430. .top-back{
  431. z-index:2;
  432. position: absolute
  433. top:261rpx;
  434. left:375rpx;
  435. height:296rpx;
  436. width:366rpx;
  437. }
  438. }
  439. </style>