restapi.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. class RestApi {
  2. //用户数据示例
  3. users = [{
  4. id: '00482',
  5. name: '李万涛',
  6. avatar: 'https://zhengda.oss-cn-chengdu.aliyuncs.com/uploads/20230417/GC5dqg8fUbgCqud5UHnKHQ5LjWymT7A0bq10XXTg.png',
  7. phone: '15609038521',
  8. },
  9. {
  10. id: '00483',
  11. name: '李万涛2',
  12. avatar: 'https://zhengda.oss-cn-chengdu.aliyuncs.com/uploads/20230319/bp8rBJyVqPWVpNaLpjLSoStk4JGmKi36tn69u8yk.png',
  13. phone: '18884559619',
  14. },
  15. ];
  16. //群数据示例
  17. // groups = [{
  18. // id: 'group-a42b-47b2-bb1e-15e0f5f9a19a',
  19. // name: '家明交流群1',
  20. // avatar: '/static/images/wx.png',
  21. // userList: [{
  22. // id: '00482',
  23. // name: '李万涛',
  24. // avatar: 'https://zhengda.oss-cn-chengdu.aliyuncs.com/uploads/20230417/GC5dqg8fUbgCqud5UHnKHQ5LjWymT7A0bq10XXTg.png',
  25. // phone: '15609038521',
  26. // },
  27. // {
  28. // id: '00483',
  29. // name: '李万涛2',
  30. // avatar: 'https://zhengda.oss-cn-chengdu.aliyuncs.com/uploads/20230319/bp8rBJyVqPWVpNaLpjLSoStk4JGmKi36tn69u8yk.png',
  31. // phone: '18884559619',
  32. // }
  33. // ],
  34. // },
  35. // {
  36. // id: 'group-4b01-4590-bdba-6586d7617f95',
  37. // name: '家明交流群2',
  38. // avatar: '/static/images/uniapp.png',
  39. // userList: [{
  40. // id: '00482',
  41. // name: '李万涛',
  42. // avatar: 'https://zhengda.oss-cn-chengdu.aliyuncs.com/uploads/20230417/GC5dqg8fUbgCqud5UHnKHQ5LjWymT7A0bq10XXTg.png',
  43. // phone: '15609038521',
  44. // },
  45. // {
  46. // id: '00483',
  47. // name: '李万涛2',
  48. // avatar: 'https://zhengda.oss-cn-chengdu.aliyuncs.com/uploads/20230319/bp8rBJyVqPWVpNaLpjLSoStk4JGmKi36tn69u8yk.png',
  49. // phone: '18884559619',
  50. // }
  51. // ]
  52. // }
  53. // ];
  54. groups = [{
  55. id: 'group-a42b-47b2-bb1e-15e0f5f9a19a',
  56. name: '家明交流群1',
  57. avatar: '/static/images/wx.png',
  58. userList: [
  59. '00482',
  60. '00483'
  61. ],
  62. },
  63. {
  64. id: 'group-4b01-4590-bdba-6586d7617f95',
  65. name: '家明交流群2',
  66. avatar: '/static/images/uniapp.png',
  67. userList: [
  68. '00482',
  69. '00483'
  70. ],
  71. },
  72. {
  73. id: 'group-dbb0-4bc9-99c6-fa77b9eb763f',
  74. name: '家明交流群3',
  75. avatar: '/static/images/goeasy.jpeg',
  76. userList: [
  77. '00482',
  78. '00483'
  79. ],
  80. }
  81. ];
  82. // 订单
  83. // orders = [{
  84. // id: '252364104325',
  85. // url: '/static/images/goods1-1.jpg',
  86. // name: '青桔柠檬气泡美式',
  87. // price: '¥23',
  88. // count: 1
  89. // },
  90. // {
  91. // id: '251662058022',
  92. // url: '/static/images/goods1-2.jpg',
  93. // name: '咸柠七',
  94. // price: '¥8',
  95. // count: 2
  96. // },
  97. // {
  98. // id: '250676186141',
  99. // url: '/static/images/goods1-3.jpg',
  100. // name: '黑糖波波鲜奶茶',
  101. // price: '¥12',
  102. // count: 1
  103. // }
  104. // ];
  105. findUsers() {
  106. return this.users;
  107. };
  108. findFriends(user) {
  109. return this.users.filter((v) => v.id !== user.id);
  110. }
  111. findGroups(user) {
  112. return this.groups.filter((v) => v.userList.find((id) => id === user.id));
  113. }
  114. findAllGroups(user) {
  115. return this.groups;
  116. }
  117. findUser(username, password) {
  118. return this.users.find((user) => user.name === username && user.password === password);
  119. }
  120. getOrderList() {
  121. return this.orders;
  122. }
  123. findGroupById(groupId) {
  124. return this.groups.find((group) => group.id === groupId);
  125. }
  126. findUserById(userId) {
  127. return this.users.find((user) => user.id === userId);
  128. }
  129. findGroupMembers(groupId) {
  130. let group = this.groups.find(v => v.id === groupId);
  131. let userIds = group.userList
  132. let members = []
  133. this.users.forEach((item, index) => {
  134. if (userIds.includes(item.id)) {
  135. members.push(item)
  136. }
  137. })
  138. return members;
  139. }
  140. }
  141. export default new RestApi();