login.vue 11 KB

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