project.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // import SHOP from '../staticURL.js'
  2. //
  3. // export default {
  4. // namespaced: true,
  5. // state: () => ({
  6. // projects: [{
  7. // "id": 2,
  8. // "name": "可乐",
  9. // "originPrice": 8,
  10. // "avatar": "",
  11. // "type":"饮料"
  12. // },
  13. // {
  14. // "id": 1,
  15. // "name": "雪碧",
  16. // "originPrice": 8,
  17. // "avatar": "",
  18. // "type":"饮料"
  19. // },
  20. // {
  21. // "id": 11,
  22. // "name": "拿铁",
  23. // "originPrice": 18,
  24. // "avatar": "",
  25. // "type":"咖啡"
  26. // },
  27. // {
  28. // "id": 12,
  29. // "name": "咖啡",
  30. // "originPrice": 18,
  31. // "avatar": "",
  32. // "type":"咖啡"
  33. // },
  34. // ] // 保存店面数据的数组
  35. // }),
  36. // mutations: {
  37. // setProjects(state, projects) {
  38. // state.projects = projects; // 更新店面数据
  39. // }
  40. // },
  41. // actions: {
  42. // //后端请求得到所有的店面的数据,保存入projects
  43. // async fetchProjects({ commit }) {
  44. // // return
  45. // try {
  46. // const response = await uni.request({
  47. // // url: uni.$http.baseUrl + 'product/selectAll',
  48. // url: SHOP.SELECTALLURL,
  49. // method: 'GET',
  50. // header: {
  51. // 'content-type': 'application/json',
  52. // 'token': uni.$http.testToken
  53. // }
  54. // });
  55. // if (response.data && response.data.code === '200') {
  56. // console.log(response.data.data);
  57. // console.log('==');
  58. // // 如果请求成功并且返回的数据中包含 code 为 '200',则提交 mutation 更新店面数据
  59. // commit('setProjects', response.data.data);
  60. // } else {
  61. // console.error('请求失败或返回的数据不符合预期');
  62. // }
  63. // } catch (error) {
  64. // console.error('请求失败:', error);
  65. // }
  66. // }
  67. // },
  68. // getters: {
  69. // // getProjectsByType: (state) => (type) => {
  70. // // if (type=='all'||type=='全部商品'){
  71. // // return state.projects
  72. // // }
  73. // // return state.projects.filter(project => project.type == type)
  74. // // },
  75. // getProjectsByType: (state) => (type) => {
  76. // type=String(type)
  77. // if (type === 'all' || type === '全部商品') {
  78. // return state.projects;
  79. // }
  80. // console.log('---------');
  81. // console.log(state.projects);
  82. // console.log(type);
  83. // console.log('---------');
  84. // return state.projects.filter(project => {
  85. // let pType = String (project.type)
  86. // const categories = pType.split(' '); // 使用空格分割多类别
  87. // return categories.includes(type); // 包含特定类别的商品
  88. // });
  89. // }
  90. // },
  91. // };