App.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <script>
  2. import {
  3. login
  4. } from '@/api/user.js'
  5. import md5 from 'js-md5'
  6. export default {
  7. onLaunch: function(options) {
  8. if(options && options.query && options.query.user){
  9. this.getUserInfo({
  10. smsCode: "",
  11. captchaKey: "",
  12. captchaValue: "",
  13. username: options.query.user,
  14. password: "",
  15. mark: ""
  16. }).then(res => {
  17. if(this.loginCallBack){
  18. this.loginCallBack()
  19. }
  20. })
  21. }
  22. },
  23. onShow: function() {
  24. let mac = this.getDeviceMac();
  25. uni.setStorageSync("mac", mac);
  26. },
  27. onHide: function() {
  28. },
  29. methods: {
  30. getUserInfo(params) {
  31. return new Promise((resolve, reject) => {
  32. login({
  33. ...params,
  34. mark: md5(params.username + 'gdnxfdexam321')
  35. }).then(res => {
  36. // 保存本地token
  37. uni.setStorageSync('token', res.token);
  38. resolve(res)
  39. }).catch(err => {
  40. reject(err)
  41. })
  42. })
  43. },
  44. //获取设备的mac地址
  45. getDeviceMac() {
  46. //获取本机Mac地址
  47. var deviceMac = 'pc';
  48. if (uni.getSystemInfoSync().platform == "android") {
  49. var net = plus.android.importClass('java.net.NetworkInterface');
  50. var wl0 = net.getByName('wlan0');
  51. var macByte = wl0.getHardwareAddress();
  52. deviceMac = '';
  53. for (var i = 0; i < macByte.length; i++) {
  54. var tmp = '';
  55. var num = macByte[i];
  56. if (num < 0) {
  57. tmp = (255 + num + 1).toString(16);
  58. } else {
  59. tmp = num.toString(16);
  60. }
  61. if (tmp.length == 1) {
  62. tmp = '0' + tmp;
  63. }
  64. deviceMac += tmp;
  65. }
  66. }
  67. return deviceMac;
  68. },
  69. }
  70. }
  71. </script>
  72. <style lang="scss">
  73. /* uni.css - 通用组件、模板样式库,可以当作一套ui库应用 */
  74. @import './style/uni.css';
  75. /* 考试相关样式 */
  76. @import './style/style.css';
  77. /* 重写样式 */
  78. .uni-load-more__text {
  79. font-size: 14px !important;
  80. }
  81. .page-box {
  82. padding: 20px;
  83. font-size: 14px;
  84. display: flex;
  85. flex-direction: column;
  86. height: 100vh;
  87. }
  88. </style>