login.vue 10 KB

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