login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. } from '@/pages/api/index.js'
  44. import {
  45. Encrypt,
  46. Decrypt
  47. } from '@/utils/secret.js'
  48. export default {
  49. data() {
  50. return {
  51. identityStatus: 1,
  52. // username:"dedsudiyu",//学生
  53. username: "01", //教职工
  54. password: "zd123456",
  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. ]).then((result) => {
  115. if (uni.getStorageSync('codeData')) {
  116. uni.redirectTo({
  117. url: '/pages/views/saoCode/saoCode',
  118. });
  119. } else if (uni.getStorageSync('warningId')) {
  120. uni.redirectTo({
  121. url: '/pages_basics/views/earlyWarningManage/earlyWarningDetail',
  122. });
  123. } else {
  124. uni.redirectTo({
  125. url: '/pages/views/home/home',
  126. });
  127. }
  128. }).catch((error) => {
  129. wx.showToast({
  130. title: '数据异常,请稍候再试!',
  131. icon: "none",
  132. duration: 3000
  133. });
  134. })
  135. }else{
  136. wx.showToast({
  137. title: '非教职工/学生账号,无法登录本系统.',
  138. icon: "none",
  139. duration: 3000
  140. });
  141. }
  142. }
  143. },
  144. //获取权限字段
  145. async systemAppletRolePermission() {
  146. let self = this;
  147. const {
  148. data
  149. } = await systemAppletRolePermission();
  150. if (data.code == 200) {
  151. uni.setStorageSync('permissions', data.data.data)
  152. uni.setStorageSync('controlsRestrict', data.data.roleKeys ? data.data.roleKeys : [])
  153. }
  154. },
  155. switchClick() {
  156. if (this.identityStatus == 1) {
  157. this.identityStatus = 2;
  158. } else {
  159. this.identityStatus = 1;
  160. }
  161. },
  162. //查询公共配置
  163. async getConfigInfo() {
  164. const {
  165. data
  166. } = await configInfo({
  167. type: '1,2,4'
  168. });
  169. if (data.code == 200) {
  170. let list = JSON.parse(data.data)
  171. let newData = {};
  172. list.forEach((item) => {
  173. let obj = JSON.parse(item.configValue)
  174. newData = {
  175. ...newData,
  176. ...obj
  177. }
  178. })
  179. uni.setStorageSync('circularLogo', config.base_url + newData.circularLogo)
  180. uni.setStorageSync('rectangleLogo', config.base_url + newData.rectangleLogo)
  181. uni.setStorageSync('videoCover', config.base_url + newData.videoCover)
  182. this.$set(this, 'loginBanner', config.base_url + newData.loginBanner);
  183. uni.setStorageSync('loginBanner', config.base_url + newData.loginBanner)
  184. this.$set(this, 'supplierType', newData.supplier);
  185. uni.setStorageSync('supplierType', newData.supplier)
  186. uni.setStorageSync('homepageBanner', config.base_url + newData.homepageBanner)
  187. }
  188. },
  189. //获取开发配置
  190. async getConfigByType() {
  191. const {
  192. data
  193. } = await getConfigByType({
  194. category: 2,
  195. configType: 5
  196. });
  197. if (data.code == 200) {
  198. let obj = JSON.parse(data.data.configValue)
  199. console.log('obj', obj)
  200. //文件预览地址
  201. uni.setStorageSync('filePreviewUrl', 'https://' + obj.fileExtranetUrl)
  202. //小程序视频地址
  203. uni.setStorageSync('cameraExtranetAgent', 'https://' + obj.cameraExtranetAgent)
  204. //MQTT地址
  205. uni.setStorageSync('mqttUrl', Decrypt(obj.mqttExtranetUrl))
  206. //MQTT账号
  207. uni.setStorageSync('mqttUser', Decrypt(obj.mqttExtranetUser))
  208. //MQTT密码
  209. uni.setStorageSync('mqttPassword', Decrypt(obj.mqttExtranetPassword))
  210. //文件浏览环境
  211. uni.setStorageSync('fileBrowseEnvironment','http://'+Decrypt(obj.fileBrowseEnvironment))
  212. uni.setStorageSync('fileBrowseEnvironmentExtranet','https://'+Decrypt(obj.fileBrowseEnvironmentExtranet))
  213. }
  214. },
  215. checkboxChange() {
  216. this.checkedType = !this.checkedType;
  217. },
  218. },
  219. }
  220. </script>
  221. <style lang="stylus" scoped>
  222. #login {
  223. height: 100%;
  224. width: 100%;
  225. background #f5f5f5;
  226. position relative;
  227. .login-max-big {
  228. width: 750rpx;
  229. height: 1177rpx;
  230. z-index: 0;
  231. }
  232. .login-box {
  233. z-index: 3;
  234. position: absolute;
  235. top: 446rpx;
  236. left: 46rpx;
  237. width: 658rpx;
  238. height: 700rpx;
  239. // background #fff
  240. /* 切换按钮 */
  241. .tabTitle {
  242. display flex;
  243. width: 100%;
  244. height: 100rpx;
  245. position: absolute;
  246. top: 50rpx;
  247. justify-content: center;
  248. .tabTitle_li {
  249. width: 168rpx;
  250. text-align center;
  251. .tabTitle_text {
  252. display: inline-block;
  253. font-size: 32rpx;
  254. font-family: PingFang SC;
  255. font-weight: 500;
  256. color: #333333;
  257. line-height: 90rpx;
  258. &.on {
  259. color: #0183FA;
  260. }
  261. }
  262. .tabTitle_across {
  263. width: 100rpx;
  264. height: 4rpx;
  265. background: #0183FA;
  266. border-radius: 2rpx;
  267. margin-left 30rpx;
  268. display none;
  269. &.on {
  270. display block;
  271. }
  272. }
  273. }
  274. }
  275. border-radius:20rpx;
  276. .input-max-box-one {
  277. overflow: hidden;
  278. margin-top: 68rpx;
  279. .input-box {
  280. display flex;
  281. width: 600rpx;
  282. height: 80rpx;
  283. border: 1rpx solid #e0e0e0;
  284. border-radius: 40rpx;
  285. margin: 147rpx auto 0;
  286. img {
  287. width: 28rpx;
  288. height: 32rpx;
  289. margin: 24rpx 31rpx;
  290. }
  291. input {
  292. flex: 1;
  293. font-size: 24rpx;
  294. height: 80rpx;
  295. line-height: 80rpx;
  296. margin-right: 31rpx;
  297. }
  298. }
  299. .text-box {
  300. height: 59rpx;
  301. line-height: 59rpx;
  302. color: #DC1616;
  303. font-size: 24rpx;
  304. margin-left: 102rpx;
  305. }
  306. }
  307. .input-max-box-two {
  308. margin-top: 40rpx;
  309. .input-box {
  310. display flex;
  311. width: 600rpx;
  312. height: 80rpx;
  313. border: 1rpx solid #e0e0e0;
  314. border-radius: 40rpx;
  315. margin: 0 auto 0;
  316. img {
  317. width: 30rpx;
  318. height: 32rpx;
  319. margin: 24rpx 30rpx;
  320. }
  321. input {
  322. flex: 1;
  323. font-size: 24rpx;
  324. height: 80rpx;
  325. line-height: 80rpx;
  326. margin-right: 31rpx;
  327. }
  328. }
  329. .text-box {
  330. height: 59rpx;
  331. line-height: 59rpx;
  332. color: #DC1616;
  333. font-size: 24rpx;
  334. margin-left: 102rpx;
  335. }
  336. }
  337. .check-box {
  338. margin: 30rpx 0 30rpx 104rpx;
  339. width: 300rpx;
  340. height: 50rpx;
  341. display: flex;
  342. img {
  343. margin-top: 10rpx;
  344. width: 32rpx;
  345. height: 32rpx;
  346. margin-right: 10rpx;
  347. }
  348. view {
  349. font-size: 24rpx;
  350. line-height: 50rpx;
  351. }
  352. }
  353. .button-box {
  354. width: 600rpx;
  355. line-height: 80rpx;
  356. background: #0183FA;
  357. border-radius: 40rpx;
  358. font-size: 36rpx;
  359. color: #fff;
  360. text-align center;
  361. margin: 0 auto 0;
  362. }
  363. /* 供应商注册 */
  364. .supplier {
  365. display: flex;
  366. justify-content: space-between;
  367. margin: 30rpx 40rpx 0;
  368. .supplier_l {
  369. font-size: 24rpx;
  370. font-family: PingFang SC;
  371. font-weight: 400;
  372. color: #333333;
  373. line-height: 24rpx;
  374. }
  375. .supplier_r {
  376. font-size: 24rpx;
  377. font-family: PingFang SC;
  378. font-weight: 400;
  379. color: #333333;
  380. line-height: 24rpx;
  381. >text {
  382. color: #0183FA;
  383. }
  384. }
  385. }
  386. /* 供应商切换 */
  387. .switch_btn {
  388. display: flex;
  389. justify-content: center;
  390. align-items: center;
  391. font-size: 24rpx;
  392. font-family: PingFang SC;
  393. font-weight: 400;
  394. color: #0183FA;
  395. line-height: 24rpx;
  396. margin-top: 60rpx;
  397. >img {
  398. width: 24rpx;
  399. height: 24rpx;
  400. margin-left: 12rpx;
  401. }
  402. }
  403. }
  404. .top-back {
  405. z-index: 2;
  406. position: absolute;
  407. top: 261rpx;
  408. left: 375rpx;
  409. height: 296rpx;
  410. width: 366rpx;
  411. }
  412. }
  413. </style>