login.vue 12 KB

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