login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <!-- 登录 -->
  2. <template>
  3. <view id="login">
  4. <img class="login-max-big" :src="loginBanner">
  5. <view class="login-box">
  6. <view class="tabTitle">
  7. <view class="tabTitle_li" @tap="tabClick(index)" :key="index" v-for="(item,index) in tabText">
  8. <view :class="{on:curTab==index}" class="tabTitle_text">{{item}}</view>
  9. <view :class="{on:curTab==index}" class="tabTitle_across"></view>
  10. </view>
  11. </view>
  12. <view class="input-max-box-one">
  13. <view class="input-box">
  14. <img src="@/pages/images/img_log_in_account.png" />
  15. <input type="text" v-model="username" placeholder="请输入账号" maxlength="20">
  16. </view>
  17. </view>
  18. <view class="input-max-box-two">
  19. <view class="input-box">
  20. <img src="@/pages/images/img_log_in_password.png" />
  21. <input type="password" v-model="password" placeholder="请输入密码" maxlength="20">
  22. </view>
  23. </view>
  24. <view class="check-box" @click="checkboxChange">
  25. <img v-if="checkedType" src="@/pages/images/icon_13.png" />
  26. <img v-if="!checkedType" src="@/pages/images/icon_12.png" />
  27. <view>记住我</view>
  28. </view>
  29. <view class="button-box" @click="login">登录</view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import md5 from '@/utils/md5.js'
  35. import {
  36. config
  37. } from '@/api/request/config.js'
  38. import {
  39. login,
  40. configInfo,
  41. getConfigByType,
  42. systemAppletRolePermission,
  43. securityDataStatisticsGetUserIdentity
  44. } from '@/pages/api/index.js'
  45. import {
  46. Encrypt,
  47. Decrypt
  48. } from '@/utils/secret.js'
  49. export default {
  50. data() {
  51. return {
  52. identityStatus: 1,
  53. username: "",
  54. password: "",
  55. checkedType: false,
  56. loginBanner: uni.getStorageSync('loginBanner'),
  57. infoList: [], //模板消息Id
  58. tabText: ['师生登录'],
  59. curTab: 0,
  60. pageType: 0,
  61. supplierType: false,
  62. }
  63. },
  64. onLoad(option) {
  65. //供应商注册成功后返回到供应商注册页面
  66. if (option.status) {
  67. this.identityStatus = 2
  68. }
  69. if (uni.getStorageSync('userName') && uni.getStorageSync('password')) {
  70. this.username = uni.getStorageSync('userName');
  71. this.password = uni.getStorageSync('password');
  72. this.checkedType = true;
  73. }
  74. },
  75. onShow() {
  76. this.getConfigInfo();
  77. },
  78. methods: {
  79. //顶部tab点击
  80. tabClick(index) {
  81. this.curTab = index;
  82. },
  83. //登录
  84. async login() {
  85. let self = this;
  86. let obj = {
  87. account: this.username,
  88. password: md5.hex_md5(this.password),
  89. }
  90. const {
  91. data
  92. } = await login(obj)
  93. if (data.code == 200) {
  94. if(data.data.userType == 1 || data.data.userType == 2){
  95. uni.setStorageSync('dataBoardType', false);
  96. uni.setStorageSync('token', data.data.token);
  97. uni.setStorageSync('userId', data.data.userId);
  98. // userType 0-系统 1-教职工 2-学生 3-大屏
  99. uni.setStorageSync('userType', data.data.userType == 0 || data.data.userType == 1 ? '1' :
  100. (data.data.userType == 2 ? '2' : (data.data.userType == 3 ? '3' : 'none')));
  101. if (this.checkedType) {
  102. uni.setStorageSync('userName', this.username)
  103. uni.setStorageSync('password', this.password)
  104. } else {
  105. uni.removeStorageSync('userName')
  106. uni.removeStorageSync('password')
  107. }
  108. //等待配置与字段获取到后跳转
  109. Promise.all([
  110. //获取开发配置
  111. this.getConfigByType(),
  112. //获取权限字段
  113. this.systemAppletRolePermission(),
  114. //查询身份
  115. this.securityDataStatisticsGetUserIdentity()
  116. ]).then((result) => {
  117. if (uni.getStorageSync('codeData')) {
  118. uni.redirectTo({
  119. url: '/pages/views/saoCode/saoCode',
  120. });
  121. } else if (uni.getStorageSync('warningId')) {
  122. uni.redirectTo({
  123. url: '/pages_basics/views/earlyWarningManage/earlyWarningDetail',
  124. });
  125. } else {
  126. uni.redirectTo({
  127. url: '/pages/views/home/home',
  128. });
  129. }
  130. }).catch((error) => {
  131. wx.showToast({
  132. title: '数据异常,请稍候再试!',
  133. icon: "none",
  134. duration: 3000
  135. });
  136. })
  137. }else{
  138. wx.showToast({
  139. title: '非教职工/学生账号,无法登录本系统.',
  140. icon: "none",
  141. duration: 3000
  142. });
  143. }
  144. }
  145. },
  146. //获取权限字段
  147. async systemAppletRolePermission() {
  148. let self = this;
  149. const {
  150. data
  151. } = await systemAppletRolePermission();
  152. if (data.code == 200) {
  153. uni.setStorageSync('permissions', data.data.data)
  154. uni.setStorageSync('controlsRestrict', data.data.roleKeys ? data.data.roleKeys : [])
  155. }
  156. },
  157. switchClick() {
  158. if (this.identityStatus == 1) {
  159. this.identityStatus = 2;
  160. } else {
  161. this.identityStatus = 1;
  162. }
  163. },
  164. //查询公共配置
  165. async getConfigInfo() {
  166. const {
  167. data
  168. } = await configInfo({
  169. type: '1,2,4'
  170. });
  171. if (data.code == 200) {
  172. let list = JSON.parse(data.data)
  173. let newData = {};
  174. list.forEach((item) => {
  175. let obj = JSON.parse(item.configValue)
  176. newData = {
  177. ...newData,
  178. ...obj
  179. }
  180. })
  181. uni.setStorageSync('circularLogo', config.base_url + newData.circularLogo)
  182. uni.setStorageSync('rectangleLogo', config.base_url + newData.rectangleLogo)
  183. uni.setStorageSync('videoCover', config.base_url + newData.videoCover)
  184. this.$set(this, 'loginBanner', config.base_url + newData.loginBanner);
  185. uni.setStorageSync('loginBanner', config.base_url + newData.loginBanner)
  186. this.$set(this, 'supplierType', newData.supplier);
  187. uni.setStorageSync('supplierType', newData.supplier)
  188. uni.setStorageSync('homepageBanner', config.base_url + newData.homepageBanner)
  189. }
  190. },
  191. //获取开发配置
  192. async getConfigByType() {
  193. const {
  194. data
  195. } = await getConfigByType({
  196. category: 2,
  197. configType: 5
  198. });
  199. if (data.code == 200) {
  200. let obj = JSON.parse(data.data.configValue)
  201. console.log('obj', obj)
  202. //文件预览地址
  203. uni.setStorageSync('filePreviewUrl', 'https://' + obj.fileExtranetUrl)
  204. //小程序视频地址
  205. uni.setStorageSync('cameraExtranetAgent', 'https://' + obj.cameraExtranetAgent)
  206. //MQTT地址
  207. uni.setStorageSync('mqttUrl', Decrypt(obj.mqttExtranetUrl))
  208. //MQTT账号
  209. uni.setStorageSync('mqttUser', Decrypt(obj.mqttExtranetUser))
  210. //MQTT密码
  211. uni.setStorageSync('mqttPassword', Decrypt(obj.mqttExtranetPassword))
  212. //文件浏览环境
  213. uni.setStorageSync('fileBrowseEnvironment','http://'+Decrypt(obj.fileBrowseEnvironment))
  214. uni.setStorageSync('fileBrowseEnvironmentExtranet','https://'+Decrypt(obj.fileBrowseEnvironmentExtranet))
  215. }
  216. },
  217. //查询身份
  218. async securityDataStatisticsGetUserIdentity(routeUrl) {
  219. let self = this;
  220. const {
  221. data
  222. } = await securityDataStatisticsGetUserIdentity();
  223. if(data.schoolAdmin){
  224. //校级管理员
  225. uni.setStorageSync('identityData',{
  226. type:'schoolAdmin'
  227. });
  228. }else if(data.collegeAdmin){
  229. //院级管理员
  230. uni.setStorageSync('identityData',{
  231. type:'collegeAdmin'
  232. });
  233. }else if(data.schoolGroup){
  234. //校级督导组
  235. uni.setStorageSync('identityData',{
  236. type:'schoolGroup',
  237. groupIds:data.groupIds
  238. });
  239. }else if(data.collegeGroup){
  240. //院级督导组
  241. uni.setStorageSync('identityData',{
  242. type:'collegeGroup',
  243. groupIds:data.groupIds
  244. });
  245. }else{
  246. uni.removeStorageSync('identityData');
  247. }
  248. },
  249. checkboxChange() {
  250. this.checkedType = !this.checkedType;
  251. },
  252. },
  253. }
  254. </script>
  255. <style lang="stylus" scoped>
  256. #login {
  257. height: 100%;
  258. width: 100%;
  259. background #f5f5f5;
  260. position relative;
  261. .login-max-big {
  262. width: 750rpx;
  263. height: 1177rpx;
  264. z-index: 0;
  265. }
  266. .login-box {
  267. z-index: 3;
  268. position: absolute;
  269. top: 446rpx;
  270. left: 46rpx;
  271. width: 658rpx;
  272. height: 700rpx;
  273. // background #fff
  274. /* 切换按钮 */
  275. .tabTitle {
  276. display flex;
  277. width: 100%;
  278. height: 100rpx;
  279. position: absolute;
  280. top: 50rpx;
  281. justify-content: center;
  282. .tabTitle_li {
  283. width: 168rpx;
  284. text-align center;
  285. .tabTitle_text {
  286. display: inline-block;
  287. font-size: 32rpx;
  288. font-family: PingFang SC;
  289. font-weight: 500;
  290. color: #333333;
  291. line-height: 90rpx;
  292. &.on {
  293. color: #0183FA;
  294. }
  295. }
  296. .tabTitle_across {
  297. width: 100rpx;
  298. height: 4rpx;
  299. background: #0183FA;
  300. border-radius: 2rpx;
  301. margin-left 30rpx;
  302. display none;
  303. &.on {
  304. display block;
  305. }
  306. }
  307. }
  308. }
  309. border-radius:20rpx;
  310. .input-max-box-one {
  311. overflow: hidden;
  312. margin-top: 68rpx;
  313. .input-box {
  314. display flex;
  315. width: 600rpx;
  316. height: 80rpx;
  317. border: 1rpx solid #e0e0e0;
  318. border-radius: 40rpx;
  319. margin: 147rpx auto 0;
  320. img {
  321. width: 28rpx;
  322. height: 32rpx;
  323. margin: 24rpx 31rpx;
  324. }
  325. input {
  326. flex: 1;
  327. font-size: 24rpx;
  328. height: 80rpx;
  329. line-height: 80rpx;
  330. margin-right: 31rpx;
  331. }
  332. }
  333. .text-box {
  334. height: 59rpx;
  335. line-height: 59rpx;
  336. color: #DC1616;
  337. font-size: 24rpx;
  338. margin-left: 102rpx;
  339. }
  340. }
  341. .input-max-box-two {
  342. margin-top: 40rpx;
  343. .input-box {
  344. display flex;
  345. width: 600rpx;
  346. height: 80rpx;
  347. border: 1rpx solid #e0e0e0;
  348. border-radius: 40rpx;
  349. margin: 0 auto 0;
  350. img {
  351. width: 30rpx;
  352. height: 32rpx;
  353. margin: 24rpx 30rpx;
  354. }
  355. input {
  356. flex: 1;
  357. font-size: 24rpx;
  358. height: 80rpx;
  359. line-height: 80rpx;
  360. margin-right: 31rpx;
  361. }
  362. }
  363. .text-box {
  364. height: 59rpx;
  365. line-height: 59rpx;
  366. color: #DC1616;
  367. font-size: 24rpx;
  368. margin-left: 102rpx;
  369. }
  370. }
  371. .check-box {
  372. margin: 30rpx 0 30rpx 104rpx;
  373. width: 300rpx;
  374. height: 50rpx;
  375. display: flex;
  376. img {
  377. margin-top: 10rpx;
  378. width: 32rpx;
  379. height: 32rpx;
  380. margin-right: 10rpx;
  381. }
  382. view {
  383. font-size: 24rpx;
  384. line-height: 50rpx;
  385. }
  386. }
  387. .button-box {
  388. width: 600rpx;
  389. line-height: 80rpx;
  390. background: #0183FA;
  391. border-radius: 40rpx;
  392. font-size: 36rpx;
  393. color: #fff;
  394. text-align center;
  395. margin: 0 auto 0;
  396. }
  397. /* 供应商注册 */
  398. .supplier {
  399. display: flex;
  400. justify-content: space-between;
  401. margin: 30rpx 40rpx 0;
  402. .supplier_l {
  403. font-size: 24rpx;
  404. font-family: PingFang SC;
  405. font-weight: 400;
  406. color: #333333;
  407. line-height: 24rpx;
  408. }
  409. .supplier_r {
  410. font-size: 24rpx;
  411. font-family: PingFang SC;
  412. font-weight: 400;
  413. color: #333333;
  414. line-height: 24rpx;
  415. >text {
  416. color: #0183FA;
  417. }
  418. }
  419. }
  420. /* 供应商切换 */
  421. .switch_btn {
  422. display: flex;
  423. justify-content: center;
  424. align-items: center;
  425. font-size: 24rpx;
  426. font-family: PingFang SC;
  427. font-weight: 400;
  428. color: #0183FA;
  429. line-height: 24rpx;
  430. margin-top: 60rpx;
  431. >img {
  432. width: 24rpx;
  433. height: 24rpx;
  434. margin-left: 12rpx;
  435. }
  436. }
  437. }
  438. .top-back {
  439. z-index: 2;
  440. position: absolute;
  441. top: 261rpx;
  442. left: 375rpx;
  443. height: 296rpx;
  444. width: 366rpx;
  445. }
  446. }
  447. </style>