getRuntimeInfo.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * 获取当前运行时环境信息
  3. */
  4. export default function getRuntimeInfo() {
  5. return new Promise(async (yes) => {
  6. let data = {
  7. 系统信息: uni.getSystemInfoSync(),
  8. 设备基础信息: uni.getDeviceInfo ? uni.getDeviceInfo() : null,
  9. 窗口信息: uni.getWindowInfo ? uni.getWindowInfo() : null,
  10. APP基础信息: uni.getAppBaseInfo ? uni.getAppBaseInfo() : null,
  11. APP授权设置: uni.getAppAuthorizeSetting ? uni.getAppAuthorizeSetting() : null,
  12. 设备设置: uni.getSystemSetting ? uni.getSystemSetting() : null,
  13. 网络状态: await getNetworkType(),
  14. 启动参数: uni.getLaunchOptionsSync(),
  15. // #ifdef APP-PLUS
  16. 其他信息: await getAppOtherInfo(),
  17. // #endif
  18. };
  19. yes(data)
  20. })
  21. }
  22. /**
  23. * 获取网络状态
  24. */
  25. function getNetworkType() {
  26. return new Promise((yes, err) => {
  27. if (!uni.getNetworkType) {
  28. return yes(null);
  29. }
  30. uni.getNetworkType({
  31. success(res) {
  32. yes(res.networkType);
  33. },
  34. fail() {
  35. yes("error");
  36. },
  37. });
  38. });
  39. }
  40. /**
  41. * 获取APP端设备其他信息
  42. */
  43. function getAppOtherInfo() {
  44. return new Promise(async (yes) => {
  45. let info = {};
  46. let getDevice = () =>
  47. new Promise((yes) => {
  48. plus.device.getInfo({
  49. success: yes,
  50. fail() {
  51. yes("plus.device.getInfo() fail");
  52. },
  53. });
  54. });
  55. let getOAID = () =>
  56. new Promise((yes) => {
  57. plus.device.getOAID({
  58. success: yes,
  59. fail() {
  60. yes("plus.device.getOAID() fail");
  61. },
  62. });
  63. });
  64. let getAAID = () =>
  65. new Promise((yes) => {
  66. plus.device.getOAID({
  67. success: yes,
  68. fail() {
  69. yes("plus.device.getOAID() fail");
  70. },
  71. });
  72. });
  73. let getDeviceId = () =>
  74. new Promise((yes) => {
  75. try {
  76. let id = plus.device.getDeviceId();
  77. yes(id);
  78. } catch (error) {
  79. yes("plus.device.getDeviceId() fail");
  80. }
  81. });
  82. try {
  83. info.getDevice = await getDevice();
  84. info.getOAID = await getOAID();
  85. info.getAAID = await getAAID();
  86. info.getDeviceId = await getDeviceId();
  87. yes(info);
  88. } catch (error) {
  89. console.log("getDeviceInfoFail", error);
  90. yes("获取设备信息失败!");
  91. }
  92. plus.device.getInfo({
  93. success(e) {
  94. info = Object.assign(info, e);
  95. plus.device.getOAID({
  96. success(e) {
  97. info = Object.assign(info, e);
  98. plus.device.getVAID({
  99. success(e) { },
  100. fail() {
  101. yes(
  102. Object.assign(info, {
  103. errMsg: "plus.device.getVAID 获取失败!",
  104. })
  105. );
  106. },
  107. });
  108. },
  109. fail() {
  110. yes(
  111. Object.assign(info, {
  112. errMsg: "plus.device.getOAID 获取失败!",
  113. })
  114. );
  115. },
  116. });
  117. },
  118. fail() {
  119. yes({ errMsg: "plus.device.getInfo 获取失败!" });
  120. },
  121. });
  122. });
  123. }