public.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. export default {
  2. data() {
  3. return {
  4. imgUrl: `${this.$config.FILE_URL}/document/newFile/download/0/${this.$config.FILE_UPLOAD_KEY}?fileKey=`,
  5. // 远程图片
  6. remoteImgUrl: `${this.$config.STATIC_IMG_URL}/`,
  7. // 云机列表
  8. cloudList: [],
  9. // 套餐类型
  10. mealTypeList: [],
  11. mealTypeObj: {},
  12. // 分组栏
  13. groupList: []
  14. }
  15. },
  16. methods: {
  17. /**
  18. * 根据卡套餐获取对应图标
  19. * @method imgFun
  20. * @param {String} type--1 套餐类型 VIP|SVIP|STARRYSKY
  21. * @param {String} androidVersion--2 安卓系统版本
  22. * @param {String} key='previewUrl'--3 ['previewUrl' | 'phonePreviewUrl'] 判断是预览图还是套餐图标用的
  23. * @returns {String} 图片路径
  24. */
  25. imgFun(type, androidVersion = '', key = 'previewUrl') {
  26. let obj = this.mealTypeObj[type + androidVersion]
  27. // obj[key]的值是default或defaultPhonePreviewUrl时候,就是后端没有返回图标还有预览图过来,显示默认的
  28. return obj[key] === 'default' ? '/static/img/userMealUpgradeVO_icon.png' : (obj[key] === 'defaultPhonePreviewUrl' ?
  29. this.remoteImgUrl + 'defalut-preview.png' : obj[key])
  30. },
  31. // 获取用户云手机列表
  32. async getCloudList() {
  33. try {
  34. const result = await this.$axios.get('/resources/v6/client/device/info/getDeviceList');
  35. if(result.status === 200 && result.data.status === 0 && result.data.success) {
  36. this.cloudList = result.data.data.diskInfo ?? [];
  37. }
  38. } catch (error) {
  39. console.error('获取云手机列表失败', error)
  40. }
  41. },
  42. // 获取云手机套餐,显示套餐名称和图标
  43. async getMealIconInfo() {
  44. try {
  45. const result = await this.$axios.get('/pay/v2/meal/info/getMealIconInfo');
  46. if(result.status === 200 && result.data.status === 0 && result.data.success) {
  47. const res = result.data;
  48. let obj = {} // eg: {VIP7: xxx, VIP10: xxx, SVIP7: xxx,...}
  49. let casualObj = {} // eg: {VIP: xxx, SVIP: xxx}
  50. let mealTypeList = [] // eg: [{label:xxx, value: xxx, previewUrl: xxx, androidVersionList: [7,10]}, ...]
  51. let mealTypeObj = {} // 同obj对象
  52. let index = 0; // 数据位置
  53. for (let i of res.data) {
  54. if (!casualObj[i.phoneType]) {
  55. casualObj[i.phoneType] = {
  56. label: i.phoneTypeName,
  57. value: i.phoneType,
  58. previewUrl: 'default',
  59. phonePreviewUrl: 'defaultPhonePreviewUrl',
  60. androidVersionList: [],
  61. index
  62. }
  63. index++
  64. }
  65. let androidVersionObj = {
  66. label: `安卓${i.androidVersion}`,
  67. value: i.androidVersion,
  68. previewUrl: i.previewUrl
  69. }
  70. casualObj[i.phoneType].androidVersionList.push(androidVersionObj)
  71. // 排序
  72. casualObj[i.phoneType].androidVersionList.sort((a, b) => a.value - b.value)
  73. if (obj[i.phoneType + i.androidVersion]) continue
  74. obj[i.phoneType + i.androidVersion] = i
  75. }
  76. mealTypeList = Object.values(casualObj);
  77. mealTypeObj = obj;
  78. Object.assign(mealTypeObj, casualObj);
  79. this.mealTypeList = mealTypeList;
  80. this.mealTypeObj = mealTypeObj;
  81. console.log('套餐图标数据', mealTypeList, mealTypeObj)
  82. }
  83. } catch (error) {
  84. console.error('获取套餐图标数据失败', error)
  85. }
  86. },
  87. // 获取云机分组标识号
  88. async getCloudGroupId() {
  89. try {
  90. const result = await this.$axios.get('/resources/v6/client/group/list');
  91. if(result.status === 200 && result.data.status === 0 && result.data.success) {
  92. // 统计所有分组的云机数量
  93. let count = result.data.data.reduce((pre, g) => {
  94. // 组合分组名称和数量
  95. g.label = `${g.groupName}(${g.groupCount})`;
  96. // 统计所有分组的云机数量
  97. return pre + g.groupCount;
  98. }, 0);
  99. result.data.data.unshift({
  100. id: -1, // -1 全部分组(前端自定义值) -10 被授权列表 0 未分组
  101. groupName: '全部分组',
  102. groupCount: count,
  103. label: `全部分组(${count})`,
  104. })
  105. this.groupList = result.data.data;
  106. }
  107. } catch (error) {
  108. }
  109. }
  110. }
  111. }