login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. getGentleIdentifier,
  43. systemAppletRolePermission
  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:"dedsudiyu",//学生
  54. username: "888", //教职工
  55. password: "zd123456",
  56. checkedType: false,
  57. loginBanner: uni.getStorageSync('loginBanner'),
  58. infoList: [], //模板消息Id
  59. tabText: ['师生登录'],
  60. curTab: 0,
  61. pageType: 0,
  62. supplierType: false,
  63. }
  64. },
  65. onLoad(option) {
  66. //供应商注册成功后返回到供应商注册页面
  67. if (option.status) {
  68. this.identityStatus = 2
  69. }
  70. if (uni.getStorageSync('userName') && uni.getStorageSync('password')) {
  71. this.username = uni.getStorageSync('userName');
  72. this.password = uni.getStorageSync('password');
  73. this.checkedType = true;
  74. }
  75. },
  76. onShow() {
  77. this.getConfigInfo();
  78. },
  79. methods: {
  80. //顶部tab点击
  81. tabClick(index) {
  82. this.curTab = index;
  83. },
  84. //登录
  85. async login() {
  86. let self = this;
  87. let obj = {
  88. account: this.username,
  89. password: md5.hex_md5(this.password),
  90. }
  91. const {
  92. data
  93. } = await login(obj)
  94. if (data.code == 200) {
  95. if(data.data.userType == 1 || data.data.userType == 2){
  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. //摄像头地址ip段
  205. uni.setStorageSync('cameraIntranetAgent', obj.cameraIntranetAgent)
  206. //摄像头访问地址
  207. uni.setStorageSync('cameraUrl', 'https://' + obj.cameraExtranetUrl)
  208. //MQTT地址
  209. uni.setStorageSync('mqttUrl', Decrypt(obj.mqttExtranetUrl))
  210. //MQTT账号
  211. uni.setStorageSync('mqttUser', Decrypt(obj.mqttExtranetUser))
  212. //MQTT密码
  213. uni.setStorageSync('mqttPassword', Decrypt(obj.mqttExtranetPassword))
  214. //文件浏览环境
  215. uni.setStorageSync('fileBrowseEnvironment','http://'+Decrypt(obj.fileBrowseEnvironment))
  216. uni.setStorageSync('fileBrowseEnvironmentExtranet','https://'+Decrypt(obj.fileBrowseEnvironmentExtranet))
  217. }
  218. },
  219. checkboxChange() {
  220. this.checkedType = !this.checkedType;
  221. },
  222. },
  223. }
  224. </script>
  225. <style lang="stylus" scoped>
  226. #login {
  227. height: 100%;
  228. width: 100%;
  229. background #f5f5f5;
  230. position relative;
  231. .login-max-big {
  232. width: 750rpx;
  233. height: 1177rpx;
  234. z-index: 0;
  235. }
  236. .login-box {
  237. z-index: 3;
  238. position: absolute;
  239. top: 446rpx;
  240. left: 46rpx;
  241. width: 658rpx;
  242. height: 700rpx;
  243. // background #fff
  244. /* 切换按钮 */
  245. .tabTitle {
  246. display flex;
  247. width: 100%;
  248. height: 100rpx;
  249. position: absolute;
  250. top: 50rpx;
  251. justify-content: center;
  252. .tabTitle_li {
  253. width: 168rpx;
  254. text-align center;
  255. .tabTitle_text {
  256. display: inline-block;
  257. font-size: 32rpx;
  258. font-family: PingFang SC;
  259. font-weight: 500;
  260. color: #333333;
  261. line-height: 90rpx;
  262. &.on {
  263. color: #0183FA;
  264. }
  265. }
  266. .tabTitle_across {
  267. width: 100rpx;
  268. height: 4rpx;
  269. background: #0183FA;
  270. border-radius: 2rpx;
  271. margin-left 30rpx;
  272. display none;
  273. &.on {
  274. display block;
  275. }
  276. }
  277. }
  278. }
  279. border-radius:20rpx;
  280. .input-max-box-one {
  281. overflow: hidden;
  282. margin-top: 68rpx;
  283. .input-box {
  284. display flex;
  285. width: 600rpx;
  286. height: 80rpx;
  287. border: 1rpx solid #e0e0e0;
  288. border-radius: 40rpx;
  289. margin: 147rpx auto 0;
  290. img {
  291. width: 28rpx;
  292. height: 32rpx;
  293. margin: 24rpx 31rpx;
  294. }
  295. input {
  296. flex: 1;
  297. font-size: 24rpx;
  298. height: 80rpx;
  299. line-height: 80rpx;
  300. margin-right: 31rpx;
  301. }
  302. }
  303. .text-box {
  304. height: 59rpx;
  305. line-height: 59rpx;
  306. color: #DC1616;
  307. font-size: 24rpx;
  308. margin-left: 102rpx;
  309. }
  310. }
  311. .input-max-box-two {
  312. margin-top: 40rpx;
  313. .input-box {
  314. display flex;
  315. width: 600rpx;
  316. height: 80rpx;
  317. border: 1rpx solid #e0e0e0;
  318. border-radius: 40rpx;
  319. margin: 0 auto 0;
  320. img {
  321. width: 30rpx;
  322. height: 32rpx;
  323. margin: 24rpx 30rpx;
  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. .check-box {
  342. margin: 30rpx 0 30rpx 104rpx;
  343. width: 300rpx;
  344. height: 50rpx;
  345. display: flex;
  346. img {
  347. margin-top: 10rpx;
  348. width: 32rpx;
  349. height: 32rpx;
  350. margin-right: 10rpx;
  351. }
  352. view {
  353. font-size: 24rpx;
  354. line-height: 50rpx;
  355. }
  356. }
  357. .button-box {
  358. width: 600rpx;
  359. line-height: 80rpx;
  360. background: #0183FA;
  361. border-radius: 40rpx;
  362. font-size: 36rpx;
  363. color: #fff;
  364. text-align center;
  365. margin: 0 auto 0;
  366. }
  367. /* 供应商注册 */
  368. .supplier {
  369. display: flex;
  370. justify-content: space-between;
  371. margin: 30rpx 40rpx 0;
  372. .supplier_l {
  373. font-size: 24rpx;
  374. font-family: PingFang SC;
  375. font-weight: 400;
  376. color: #333333;
  377. line-height: 24rpx;
  378. }
  379. .supplier_r {
  380. font-size: 24rpx;
  381. font-family: PingFang SC;
  382. font-weight: 400;
  383. color: #333333;
  384. line-height: 24rpx;
  385. >text {
  386. color: #0183FA;
  387. }
  388. }
  389. }
  390. /* 供应商切换 */
  391. .switch_btn {
  392. display: flex;
  393. justify-content: center;
  394. align-items: center;
  395. font-size: 24rpx;
  396. font-family: PingFang SC;
  397. font-weight: 400;
  398. color: #0183FA;
  399. line-height: 24rpx;
  400. margin-top: 60rpx;
  401. >img {
  402. width: 24rpx;
  403. height: 24rpx;
  404. margin-left: 12rpx;
  405. }
  406. }
  407. }
  408. .top-back {
  409. z-index: 2;
  410. position: absolute;
  411. top: 261rpx;
  412. left: 375rpx;
  413. height: 296rpx;
  414. width: 366rpx;
  415. }
  416. }
  417. </style>