restapi.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //用户数据示例
  2. let users = [
  3. {
  4. "uuid": "08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a",
  5. "name": "Mattie",
  6. "password": "123",
  7. "avatar": '../static/images_go/Avatar-1.png'
  8. },
  9. {
  10. "uuid": "3bb179af-bcc5-4fe0-9dac-c05688484649",
  11. "name": "Wallace",
  12. "password": "123",
  13. "avatar": '../static/images_go/Avatar-2.png'
  14. },
  15. {
  16. "uuid": "fdee46b0-4b01-4590-bdba-6586d7617f95",
  17. "name": "Tracy",
  18. "password": "123",
  19. "avatar": '/static/images/Avatar-3.png'
  20. },
  21. {
  22. "uuid": "33c3693b-dbb0-4bc9-99c6-fa77b9eb763f",
  23. "name": "Juanita",
  24. "password": "123",
  25. "avatar": '/static/images/Avatar-4.png'
  26. }
  27. ];
  28. //群数据示例
  29. let groups = [
  30. {
  31. "uuid": "group-a42b-47b2-bb1e-15e0f5f9a19a",
  32. "name": "小程序交流群",
  33. "avatar" : '/static/images/wx.png',
  34. "userList": ['08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a', '3bb179af-bcc5-4fe0-9dac-c05688484649', 'fdee46b0-4b01-4590-bdba-6586d7617f95', '33c3693b-dbb0-4bc9-99c6-fa77b9eb763f']
  35. },
  36. {
  37. "uuid": "group-4b01-4590-bdba-6586d7617f95",
  38. "name": "UniApp交流群",
  39. "avatar" : '/static/images/uniapp.png',
  40. "userList": ['08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a', 'fdee46b0-4b01-4590-bdba-6586d7617f95', '33c3693b-dbb0-4bc9-99c6-fa77b9eb763f']
  41. },
  42. {
  43. "uuid": "group-dbb0-4bc9-99c6-fa77b9eb763f",
  44. "name": "GoEasy交流群",
  45. "avatar" : '/static/images/goeasy.jpeg',
  46. "userList": ['08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a', '3bb179af-bcc5-4fe0-9dac-c05688484649']
  47. }
  48. ];
  49. function RestApi() {
  50. }
  51. RestApi.prototype.findFriends = function (user) {
  52. var friendList = users.filter(v => v.uuid != user.uuid);
  53. return friendList;
  54. }
  55. RestApi.prototype.findGroups = function (user) {
  56. var groupList = groups.filter(v => v.userList.find(id => id == user.uuid));
  57. return groupList;
  58. }
  59. RestApi.prototype.findUser = function (username, password) {
  60. let user = users.find(user => (user.name === username && user.password === password));
  61. if(user) {
  62. return {
  63. uuid : user.uuid,
  64. avatar : user.avatar,
  65. name : user.name
  66. };
  67. }
  68. return user;
  69. }
  70. RestApi.prototype.findGroupById = function (groupId) {
  71. var group = groups.find(group => (group.uuid == groupId));
  72. return group;
  73. };
  74. RestApi.prototype.findUserById = function (userId) {
  75. var user = users.find(user => (user.uuid == userId))
  76. return user;
  77. };
  78. RestApi.prototype.findGroupMembers = function (groupId) {
  79. let members = [];
  80. let group = groups.find(v => v.uuid == groupId);
  81. users.map(user => {
  82. if (group.userList.find(v => v == user.uuid)) {
  83. members.push(user)
  84. }
  85. });
  86. return members;
  87. }
  88. export default new RestApi();