login.vue 9.5 KB

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