login.vue 10.0 KB

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