login.vue 11 KB

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