login.vue 9.9 KB

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