login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. //文件预览地址
  202. uni.setStorageSync('filePreviewUrl', 'https://' + obj.fileExtranetUrl)
  203. //小程序视频地址
  204. uni.setStorageSync('cameraExtranetAgent', 'https://' + obj.cameraExtranetAgent)
  205. //MQTT地址
  206. uni.setStorageSync('mqttUrl', Decrypt(obj.mqttExtranetUrl))
  207. //MQTT地址-内网
  208. uni.setStorageSync('mqttIntranetUrl', Decrypt(obj.mqttIntranetUrl))
  209. //MQTT账号
  210. uni.setStorageSync('mqttUser', Decrypt(obj.mqttExtranetUser))
  211. //MQTT密码
  212. uni.setStorageSync('mqttPassword', Decrypt(obj.mqttExtranetPassword))
  213. //文件浏览环境
  214. uni.setStorageSync('fileBrowseEnvironment','http://'+Decrypt(obj.fileBrowseEnvironment))
  215. uni.setStorageSync('fileBrowseEnvironmentExtranet','https://'+Decrypt(obj.fileBrowseEnvironmentExtranet))
  216. }
  217. },
  218. //查询身份
  219. async securityDataStatisticsGetUserIdentity(routeUrl) {
  220. let self = this;
  221. const {
  222. data
  223. } = await securityDataStatisticsGetUserIdentity();
  224. if(data.schoolAdmin){
  225. //校级管理员
  226. uni.setStorageSync('identityData',{
  227. type:'schoolAdmin'
  228. });
  229. }else if(data.collegeAdmin){
  230. //院级管理员
  231. uni.setStorageSync('identityData',{
  232. type:'collegeAdmin'
  233. });
  234. }else if(data.schoolGroup){
  235. //校级督导组
  236. uni.setStorageSync('identityData',{
  237. type:'schoolGroup',
  238. groupIds:data.groupIds
  239. });
  240. }else if(data.collegeGroup){
  241. //院级督导组
  242. uni.setStorageSync('identityData',{
  243. type:'collegeGroup',
  244. groupIds:data.groupIds
  245. });
  246. }else{
  247. uni.removeStorageSync('identityData');
  248. }
  249. },
  250. checkboxChange() {
  251. this.checkedType = !this.checkedType;
  252. },
  253. },
  254. }
  255. </script>
  256. <style lang="stylus" scoped>
  257. #login {
  258. height: 100%;
  259. width: 100%;
  260. background #f5f5f5;
  261. position relative;
  262. .login-max-big {
  263. width: 750rpx;
  264. height: 1177rpx;
  265. z-index: 0;
  266. }
  267. .login-box {
  268. z-index: 3;
  269. position: absolute;
  270. top: 446rpx;
  271. left: 46rpx;
  272. width: 658rpx;
  273. height: 700rpx;
  274. // background #fff
  275. /* 切换按钮 */
  276. .tabTitle {
  277. display flex;
  278. width: 100%;
  279. height: 100rpx;
  280. position: absolute;
  281. top: 50rpx;
  282. justify-content: center;
  283. .tabTitle_li {
  284. width: 168rpx;
  285. text-align center;
  286. .tabTitle_text {
  287. display: inline-block;
  288. font-size: 32rpx;
  289. font-family: PingFang SC;
  290. font-weight: 500;
  291. color: #333333;
  292. line-height: 90rpx;
  293. &.on {
  294. color: #0183FA;
  295. }
  296. }
  297. .tabTitle_across {
  298. width: 100rpx;
  299. height: 4rpx;
  300. background: #0183FA;
  301. border-radius: 2rpx;
  302. margin-left 30rpx;
  303. display none;
  304. &.on {
  305. display block;
  306. }
  307. }
  308. }
  309. }
  310. border-radius:20rpx;
  311. .input-max-box-one {
  312. overflow: hidden;
  313. margin-top: 68rpx;
  314. .input-box {
  315. display flex;
  316. width: 600rpx;
  317. height: 80rpx;
  318. border: 1rpx solid #e0e0e0;
  319. border-radius: 40rpx;
  320. margin: 147rpx auto 0;
  321. img {
  322. width: 28rpx;
  323. height: 32rpx;
  324. margin: 24rpx 31rpx;
  325. }
  326. input {
  327. flex: 1;
  328. font-size: 24rpx;
  329. height: 80rpx;
  330. line-height: 80rpx;
  331. margin-right: 31rpx;
  332. }
  333. }
  334. .text-box {
  335. height: 59rpx;
  336. line-height: 59rpx;
  337. color: #DC1616;
  338. font-size: 24rpx;
  339. margin-left: 102rpx;
  340. }
  341. }
  342. .input-max-box-two {
  343. margin-top: 40rpx;
  344. .input-box {
  345. display flex;
  346. width: 600rpx;
  347. height: 80rpx;
  348. border: 1rpx solid #e0e0e0;
  349. border-radius: 40rpx;
  350. margin: 0 auto 0;
  351. img {
  352. width: 30rpx;
  353. height: 32rpx;
  354. margin: 24rpx 30rpx;
  355. }
  356. input {
  357. flex: 1;
  358. font-size: 24rpx;
  359. height: 80rpx;
  360. line-height: 80rpx;
  361. margin-right: 31rpx;
  362. }
  363. }
  364. .text-box {
  365. height: 59rpx;
  366. line-height: 59rpx;
  367. color: #DC1616;
  368. font-size: 24rpx;
  369. margin-left: 102rpx;
  370. }
  371. }
  372. .check-box {
  373. margin: 30rpx 0 30rpx 104rpx;
  374. width: 300rpx;
  375. height: 50rpx;
  376. display: flex;
  377. img {
  378. margin-top: 10rpx;
  379. width: 32rpx;
  380. height: 32rpx;
  381. margin-right: 10rpx;
  382. }
  383. view {
  384. font-size: 24rpx;
  385. line-height: 50rpx;
  386. }
  387. }
  388. .button-box {
  389. width: 600rpx;
  390. line-height: 80rpx;
  391. background: #0183FA;
  392. border-radius: 40rpx;
  393. font-size: 36rpx;
  394. color: #fff;
  395. text-align center;
  396. margin: 0 auto 0;
  397. }
  398. /* 供应商注册 */
  399. .supplier {
  400. display: flex;
  401. justify-content: space-between;
  402. margin: 30rpx 40rpx 0;
  403. .supplier_l {
  404. font-size: 24rpx;
  405. font-family: PingFang SC;
  406. font-weight: 400;
  407. color: #333333;
  408. line-height: 24rpx;
  409. }
  410. .supplier_r {
  411. font-size: 24rpx;
  412. font-family: PingFang SC;
  413. font-weight: 400;
  414. color: #333333;
  415. line-height: 24rpx;
  416. >text {
  417. color: #0183FA;
  418. }
  419. }
  420. }
  421. /* 供应商切换 */
  422. .switch_btn {
  423. display: flex;
  424. justify-content: center;
  425. align-items: center;
  426. font-size: 24rpx;
  427. font-family: PingFang SC;
  428. font-weight: 400;
  429. color: #0183FA;
  430. line-height: 24rpx;
  431. margin-top: 60rpx;
  432. >img {
  433. width: 24rpx;
  434. height: 24rpx;
  435. margin-left: 12rpx;
  436. }
  437. }
  438. }
  439. .top-back {
  440. z-index: 2;
  441. position: absolute;
  442. top: 261rpx;
  443. left: 375rpx;
  444. height: 296rpx;
  445. width: 366rpx;
  446. }
  447. }
  448. </style>