login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. export default {
  39. data() {
  40. return {
  41. identityStatus:1,
  42. username:"",
  43. password:"",
  44. checkedType:false,
  45. loginBanner:uni.getStorageSync('loginBanner'),
  46. infoList:[],//模板消息Id
  47. }
  48. },
  49. onLoad(option) {
  50. //供应商注册成功后返回到供应商注册页面
  51. if(option.status){
  52. this.identityStatus=2
  53. }
  54. if(uni.getStorageSync('userName') && uni.getStorageSync('password')){
  55. this.username = uni.getStorageSync('userName');
  56. this.password = uni.getStorageSync('password');
  57. this.checkedType = true;
  58. }
  59. },
  60. onShow(){
  61. this.getLogoInfo();
  62. this.getUrlConfig();
  63. },
  64. methods: {
  65. //获取openID
  66. async getOpenId(){
  67. let _this=this;
  68. let code=uni.getStorageSync('code')
  69. const {data} = await getOpenId({code:code});
  70. if(data.code==200){
  71. }else if(data.code==500){
  72. console.log(data.msg)
  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',data.data.mqttExtranetUrl)
  104. //MQTT账号
  105. uni.setStorageSync('mqttUser',data.data.mqttExtranetUser)
  106. //MQTT密码
  107. uni.setStorageSync('mqttPassword',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. console.log('用户点击确定');
  127. }
  128. }
  129. });
  130. }
  131. },
  132. async login() {
  133. let self = this;
  134. let obj = {
  135. username:this.username,
  136. password:this.password,
  137. }
  138. const {data} = await login(obj)
  139. if(data.code == 200){
  140. uni.setStorageSync('token','Bearer '+data.data.access_token);
  141. uni.setStorageSync('userId',data.data.user_id);
  142. this.getOpenId();//获取openid
  143. if(data.data.type == "00" ||data.data.type == "11"){//管理端
  144. uni.setStorageSync('userType',"1");
  145. this.getToken()//订阅消息
  146. }else if(data.data.type == 22){//学生端
  147. uni.setStorageSync('userType',"2");
  148. this.getToken()//订阅消息
  149. }else if(data.data.type == 33){//供应商端
  150. uni.setStorageSync('userType',"3");
  151. this.getToken2()//订阅消息
  152. }
  153. if(this.checkedType){
  154. uni.setStorageSync('userName',this.username)
  155. uni.setStorageSync('password',this.password)
  156. }else{
  157. uni.removeStorageSync('userName')
  158. uni.removeStorageSync('password')
  159. }
  160. if(uni.getStorageSync('saoCode')){
  161. uni.redirectTo({
  162. url: '/pages/saoCode/saoCode'
  163. });
  164. }else if(uni.getStorageSync('mid')){
  165. uni.redirectTo({
  166. url: '/pages_student/mine/codeSuccess'
  167. });
  168. }else if(uni.getStorageSync('saoCodeId')){
  169. uni.redirectTo({
  170. url: '/pages_manage/workbench/laboratory/laboratoryInfo'
  171. });
  172. }else{
  173. uni.redirectTo({
  174. url: '/pages/home',
  175. });
  176. }
  177. }
  178. },
  179. //订阅列表查询
  180. async getInfoListId(){
  181. let _this = this;
  182. const {data} = await getDemoInfoList(this.getData)
  183. if(data.code==200){
  184. let _this=this;
  185. let res =data.data
  186. //_this.getToken(res)
  187. }
  188. },
  189. //学生端和管理端订阅消息,出库确认通知,审核结果通知,待审核通知
  190. getToken() {
  191. let _this = this
  192. wx.requestSubscribeMessage({
  193. tmplIds:['Vg6iHUEg6hor7RvP37M7oFCoYGreCu11apJqRB2j37w','0gFoOByDYhCOthJW0tgUi3SHTkLMUK11EfIYlS_qJi4','6yzAPx_o9jn_2xhTt7blDcxjYD1x0vUV1JxUsKqpG4k'],//此处的id替换你要发送订阅的模板id,可在小程序后台新建模板中获取
  194. success(res) {
  195. if(res.errMsg=='requestSubscribeMessage:ok'){
  196. uni.showToast({
  197. title:'订阅成功!',
  198. icon:"none",
  199. mask:true,
  200. duration: 2000
  201. });
  202. }
  203. },
  204. fail: function(res) {
  205. console.log(res)
  206. }
  207. })
  208. },
  209. //供应商端订阅消息,待办事项通知
  210. getToken2() {
  211. let _this = this
  212. wx.requestSubscribeMessage({
  213. tmplIds:['2HtEIQ3_PmS0yMd3PHPIIawRqnSP0_He5wrhVKeuqaw'],//此处的id替换你要发送订阅的模板id,可在小程序后台新建模板中获取
  214. success(res) {
  215. if(res.errMsg=='requestSubscribeMessage:ok'){
  216. uni.showToast({
  217. title:'订阅成功!',
  218. icon:"none",
  219. mask:true,
  220. duration: 2000
  221. });
  222. }
  223. },
  224. fail: function(res) {
  225. console.log(res)
  226. }
  227. })
  228. }
  229. },
  230. }
  231. </script>
  232. <style lang="stylus" scoped>
  233. #login{
  234. height:100%;
  235. width:100%;
  236. background #f5f5f5
  237. position relative
  238. .login-max-big{
  239. width:750rpx;
  240. height:1177rpx;
  241. z-index:0;
  242. }
  243. .login-box{
  244. z-index:1;
  245. position: absolute
  246. top:446rpx;
  247. left:46rpx;
  248. width:658rpx;
  249. height:700rpx;
  250. // background #fff
  251. border-radius:20rpx;
  252. .input-max-box-one{
  253. .input-box{
  254. display flex
  255. width:600rpx;
  256. height:80rpx;
  257. border:1rpx solid #e0e0e0;
  258. border-radius:40rpx;
  259. margin:147rpx auto 0;
  260. img{
  261. width:28rpx;
  262. height:32rpx;
  263. margin:24rpx 31rpx;
  264. }
  265. input{
  266. flex:1;
  267. font-size:24rpx;
  268. height:80rpx;
  269. line-height:80rpx;
  270. margin-right:31rpx;
  271. }
  272. }
  273. .text-box{
  274. height:59rpx;
  275. line-height:59rpx;
  276. color:#DC1616;
  277. font-size:24rpx;
  278. margin-left:102rpx;
  279. }
  280. }
  281. .input-max-box-two{
  282. margin-top:40rpx;
  283. .input-box{
  284. display flex
  285. width:600rpx;
  286. height:80rpx;
  287. border:1rpx solid #e0e0e0;
  288. border-radius:40rpx;
  289. margin:0 auto 0;
  290. img{
  291. width:30rpx;
  292. height:32rpx;
  293. margin:24rpx 30rpx;
  294. }
  295. input{
  296. flex:1;
  297. font-size:24rpx;
  298. height:80rpx;
  299. line-height:80rpx;
  300. margin-right:31rpx;
  301. }
  302. }
  303. .text-box{
  304. height:59rpx;
  305. line-height:59rpx;
  306. color:#DC1616;
  307. font-size:24rpx;
  308. margin-left:102rpx;
  309. }
  310. }
  311. .check-box{
  312. margin:30rpx 0 30rpx 104rpx;
  313. width:300rpx;
  314. height:50rpx;
  315. display:flex;
  316. img{
  317. margin-top:10rpx;
  318. width:32rpx;
  319. height:32rpx;
  320. margin-right:10rpx;
  321. }
  322. view{
  323. font-size:24rpx;
  324. line-height:50rpx;
  325. }
  326. }
  327. .button-box{
  328. width: 600rpx;
  329. line-height: 80rpx;
  330. background: #0183FA;
  331. border-radius: 40rpx;
  332. font-size: 36rpx;
  333. color:#fff;
  334. text-align center
  335. margin:0 auto 0;
  336. }
  337. /* 供应商注册 */
  338. .supplier{
  339. display: flex;
  340. justify-content: space-between;
  341. margin:30rpx 40rpx 0;
  342. .supplier_l{
  343. font-size: 24rpx;
  344. font-family: PingFang SC;
  345. font-weight: 400;
  346. color: #333333;
  347. line-height: 24rpx;
  348. }
  349. .supplier_r{
  350. font-size: 24rpx;
  351. font-family: PingFang SC;
  352. font-weight: 400;
  353. color: #333333;
  354. line-height: 24rpx;
  355. >text{
  356. color: #0183FA;
  357. }
  358. }
  359. }
  360. /* 供应商切换 */
  361. .switch_btn{
  362. display: flex;
  363. justify-content: center;
  364. align-items: center;
  365. font-size: 24rpx;
  366. font-family: PingFang SC;
  367. font-weight: 400;
  368. color: #0183FA;
  369. line-height: 24rpx;
  370. margin-top: 60rpx;
  371. >img{
  372. width: 24rpx;
  373. height: 24rpx;
  374. margin-left: 12rpx;
  375. }
  376. }
  377. }
  378. .top-back{
  379. z-index:2;
  380. position: absolute
  381. top:261rpx;
  382. left:375rpx;
  383. height:296rpx;
  384. width:366rpx;
  385. }
  386. }
  387. </style>