login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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 class="button-box" @click="getCode">huoqu </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import md5 from '@/utils/md5.js'
  36. import {
  37. config
  38. } from '@/api/request/config.js'
  39. import {
  40. login,
  41. configInfo,
  42. getConfigByType,
  43. getGentleIdentifier,
  44. systemAppletRolePermission
  45. } from '@/api/basicsModules/index.js'
  46. import {
  47. Encrypt,
  48. Decrypt
  49. } from '@/utils/secret.js'
  50. export default {
  51. data() {
  52. return {
  53. identityStatus: 1,
  54. // username:"superadmin",
  55. // password:"zd123456",
  56. username: "sudiyu",
  57. password: "zd123456",
  58. checkedType: false,
  59. loginBanner: uni.getStorageSync('loginBanner'),
  60. infoList: [], //模板消息Id
  61. tabText: ['师生登录'],
  62. curTab: 0,
  63. pageType: 0,
  64. supplierType: false,
  65. }
  66. },
  67. onLoad(option) {
  68. //供应商注册成功后返回到供应商注册页面
  69. if (option.status) {
  70. this.identityStatus = 2
  71. }
  72. if (uni.getStorageSync('userName') && uni.getStorageSync('password')) {
  73. this.username = uni.getStorageSync('userName');
  74. this.password = uni.getStorageSync('password');
  75. this.checkedType = true;
  76. }
  77. },
  78. onShow() {
  79. // this.getConfigInfo();
  80. // #ifdef MP-WEIXIN
  81. uni.login({
  82. "provider": "weixin",
  83. "onlyAuthorize": true, // 微信登录仅请求授权认证
  84. success: function(event) {
  85. const {
  86. code
  87. } = event
  88. console.log(code)
  89. },
  90. fail: function(err) {
  91. // 登录授权失败
  92. // err.code是错误码
  93. }
  94. })
  95. // #endif
  96. // #ifdef H5
  97. // #endif
  98. },
  99. methods: {
  100. getCode(){
  101. const appid = 'YOUR_APP_ID';
  102. const redirectUri = encodeURIComponent('http://yourwebsite.com/callback.html');
  103. const authUrl =
  104. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`;
  105. window.location.href = authUrl;
  106. },
  107. //顶部tab点击
  108. tabClick(index) {
  109. this.curTab = index;
  110. },
  111. //登录
  112. async login() {
  113. let self = this;
  114. let obj = {
  115. account: this.username,
  116. password: md5.hex_md5(this.password),
  117. }
  118. const {
  119. data
  120. } = await login(obj)
  121. if (data.code == 200) {
  122. uni.setStorageSync('token', data.data.token);
  123. uni.setStorageSync('userId', data.data.userId);
  124. // userType 0-系统 1-教职工 2-学生 3-大屏
  125. uni.setStorageSync('userType', data.data.userType == 0 || data.data.userType == 1 ? '1' :
  126. (data.data.userType == 2 ? '2' : (data.data.userType == 3 ? '3' : 'none')));
  127. if (this.checkedType) {
  128. uni.setStorageSync('userName', this.username)
  129. uni.setStorageSync('password', this.password)
  130. } else {
  131. uni.removeStorageSync('userName')
  132. uni.removeStorageSync('password')
  133. }
  134. //等待配置与字段获取到后跳转
  135. Promise.all([
  136. //获取开发配置
  137. this.getConfigByType(),
  138. //获取权限字段
  139. this.systemAppletRolePermission()
  140. ]).then((result) => {
  141. if (uni.getStorageSync('codeData')) {
  142. uni.redirectTo({
  143. url: '/pages/saoCode/saoCode',
  144. });
  145. } else {
  146. uni.redirectTo({
  147. url: '/pages/mine/mine',
  148. });
  149. }
  150. }).catch((error) => {
  151. wx.showToast({
  152. title: '数据异常,请稍候再试!',
  153. icon: "none",
  154. duration: 3000
  155. });
  156. })
  157. //获取身份标识
  158. // this.getGentleIdentifier();
  159. }
  160. },
  161. //获取权限字段
  162. async systemAppletRolePermission() {
  163. let self = this;
  164. const {
  165. data
  166. } = await systemAppletRolePermission();
  167. if (data.code == 200) {
  168. uni.setStorageSync('permissions', data.data.data)
  169. }
  170. },
  171. switchClick() {
  172. if (this.identityStatus == 1) {
  173. this.identityStatus = 2;
  174. } else {
  175. this.identityStatus = 1;
  176. }
  177. },
  178. //查询公共配置
  179. async getConfigInfo() {
  180. const {
  181. data
  182. } = await configInfo({
  183. type: '1,2,4'
  184. });
  185. if (data.code == 200) {
  186. let list = JSON.parse(data.data)
  187. let newData = {};
  188. list.forEach((item) => {
  189. let obj = JSON.parse(item.configValue)
  190. newData = {
  191. ...newData,
  192. ...obj
  193. }
  194. })
  195. uni.setStorageSync('circularLogo', config.base_url + newData.circularLogo)
  196. uni.setStorageSync('videoCover', config.base_url + newData.videoCover)
  197. this.$set(this, 'loginBanner', config.base_url + newData.loginBanner);
  198. uni.setStorageSync('loginBanner', config.base_url + newData.loginBanner)
  199. this.$set(this, 'supplierType', newData.supplier);
  200. uni.setStorageSync('supplierType', newData.supplier)
  201. uni.setStorageSync('homepageBanner', config.base_url + newData.homepageBanner)
  202. }
  203. },
  204. //获取开发配置
  205. async getConfigByType() {
  206. const {
  207. data
  208. } = await getConfigByType({
  209. category: 2,
  210. configType: 5
  211. });
  212. if (data.code == 200) {
  213. let obj = JSON.parse(data.data.configValue)
  214. //文件预览地址
  215. uni.setStorageSync('filePreviewUrl', 'https://' + obj.fileExtranetUrl)
  216. //摄像头代理访问地址
  217. uni.setStorageSync('cameraExtranetAgent', 'https://' + obj.cameraExtranetAgent)
  218. //摄像头地址ip段
  219. uni.setStorageSync('cameraIntranetAgent', obj.cameraIntranetAgent)
  220. //摄像头访问地址
  221. uni.setStorageSync('cameraUrl', 'https://' + obj.cameraExtranetUrl)
  222. //MQTT地址
  223. uni.setStorageSync('mqttUrl', Decrypt(obj.mqttExtranetUrl))
  224. //MQTT账号
  225. uni.setStorageSync('mqttUser', Decrypt(obj.mqttExtranetUser))
  226. //MQTT密码
  227. uni.setStorageSync('mqttPassword', Decrypt(obj.mqttExtranetPassword))
  228. }
  229. },
  230. checkboxChange() {
  231. this.checkedType = !this.checkedType;
  232. },
  233. },
  234. }
  235. </script>
  236. <style lang="stylus" scoped>
  237. #login {
  238. height: 100%;
  239. width: 100%;
  240. background #f5f5f5;
  241. position relative;
  242. .login-max-big {
  243. width: 750rpx;
  244. height: 1177rpx;
  245. z-index: 0;
  246. }
  247. .login-box {
  248. z-index: 3;
  249. position: absolute;
  250. top: 446rpx;
  251. left: 46rpx;
  252. width: 658rpx;
  253. height: 700rpx;
  254. // background #fff
  255. /* 切换按钮 */
  256. .tabTitle {
  257. display flex;
  258. width: 100%;
  259. height: 100rpx;
  260. position: absolute;
  261. top: 50rpx;
  262. justify-content: center;
  263. .tabTitle_li {
  264. width: 168rpx;
  265. text-align center;
  266. .tabTitle_text {
  267. display: inline-block;
  268. font-size: 32rpx;
  269. font-family: PingFang SC;
  270. font-weight: 500;
  271. color: #333333;
  272. line-height: 90rpx;
  273. &.on {
  274. color: #0183FA;
  275. }
  276. }
  277. .tabTitle_across {
  278. width: 100rpx;
  279. height: 4rpx;
  280. background: #0183FA;
  281. border-radius: 2rpx;
  282. margin-left 30rpx;
  283. display none;
  284. &.on {
  285. display block;
  286. }
  287. }
  288. }
  289. }
  290. border-radius:20rpx;
  291. .input-max-box-one {
  292. overflow: hidden;
  293. margin-top: 68rpx;
  294. .input-box {
  295. display flex;
  296. width: 600rpx;
  297. height: 80rpx;
  298. border: 1rpx solid #e0e0e0;
  299. border-radius: 40rpx;
  300. margin: 147rpx auto 0;
  301. img {
  302. width: 28rpx;
  303. height: 32rpx;
  304. margin: 24rpx 31rpx;
  305. }
  306. input {
  307. flex: 1;
  308. font-size: 24rpx;
  309. height: 80rpx;
  310. line-height: 80rpx;
  311. margin-right: 31rpx;
  312. }
  313. }
  314. .text-box {
  315. height: 59rpx;
  316. line-height: 59rpx;
  317. color: #DC1616;
  318. font-size: 24rpx;
  319. margin-left: 102rpx;
  320. }
  321. }
  322. .input-max-box-two {
  323. margin-top: 40rpx;
  324. .input-box {
  325. display flex;
  326. width: 600rpx;
  327. height: 80rpx;
  328. border: 1rpx solid #e0e0e0;
  329. border-radius: 40rpx;
  330. margin: 0 auto 0;
  331. img {
  332. width: 30rpx;
  333. height: 32rpx;
  334. margin: 24rpx 30rpx;
  335. }
  336. input {
  337. flex: 1;
  338. font-size: 24rpx;
  339. height: 80rpx;
  340. line-height: 80rpx;
  341. margin-right: 31rpx;
  342. }
  343. }
  344. .text-box {
  345. height: 59rpx;
  346. line-height: 59rpx;
  347. color: #DC1616;
  348. font-size: 24rpx;
  349. margin-left: 102rpx;
  350. }
  351. }
  352. .check-box {
  353. margin: 30rpx 0 30rpx 104rpx;
  354. width: 300rpx;
  355. height: 50rpx;
  356. display: flex;
  357. img {
  358. margin-top: 10rpx;
  359. width: 32rpx;
  360. height: 32rpx;
  361. margin-right: 10rpx;
  362. }
  363. view {
  364. font-size: 24rpx;
  365. line-height: 50rpx;
  366. }
  367. }
  368. .button-box {
  369. width: 600rpx;
  370. line-height: 80rpx;
  371. background: #0183FA;
  372. border-radius: 40rpx;
  373. font-size: 36rpx;
  374. color: #fff;
  375. text-align center;
  376. margin: 0 auto 0;
  377. }
  378. /* 供应商注册 */
  379. .supplier {
  380. display: flex;
  381. justify-content: space-between;
  382. margin: 30rpx 40rpx 0;
  383. .supplier_l {
  384. font-size: 24rpx;
  385. font-family: PingFang SC;
  386. font-weight: 400;
  387. color: #333333;
  388. line-height: 24rpx;
  389. }
  390. .supplier_r {
  391. font-size: 24rpx;
  392. font-family: PingFang SC;
  393. font-weight: 400;
  394. color: #333333;
  395. line-height: 24rpx;
  396. >text {
  397. color: #0183FA;
  398. }
  399. }
  400. }
  401. /* 供应商切换 */
  402. .switch_btn {
  403. display: flex;
  404. justify-content: center;
  405. align-items: center;
  406. font-size: 24rpx;
  407. font-family: PingFang SC;
  408. font-weight: 400;
  409. color: #0183FA;
  410. line-height: 24rpx;
  411. margin-top: 60rpx;
  412. >img {
  413. width: 24rpx;
  414. height: 24rpx;
  415. margin-left: 12rpx;
  416. }
  417. }
  418. }
  419. .top-back {
  420. z-index: 2;
  421. position: absolute;
  422. top: 261rpx;
  423. left: 375rpx;
  424. height: 296rpx;
  425. width: 366rpx;
  426. }
  427. }
  428. </style>