Collection.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { defineStore } from 'pinia'
  2. import { reactive } from 'vue'
  3. import { createCollection, deleteCollection, queryCollection, updateCollection } from '@/api/collection'
  4. export const collectionOperate = defineStore('payment', () => {
  5. // 定义数据
  6. const paymentList = reactive([])
  7. // 定义修改数据的方法
  8. const getPaymentList = (code) => {
  9. queryCollection(code).then(res => {
  10. if (res.code === 0) {
  11. paymentList.length = 0
  12. paymentList.push(...res.data)
  13. console.log(paymentList)
  14. }
  15. })
  16. }
  17. const postCollection = (data) => {
  18. createCollection(data).then(res => {
  19. if (res.code === 0) {
  20. console.log(res.data)
  21. }
  22. })
  23. }
  24. const putCollection = (data) => {
  25. updateCollection(data).then(res => {
  26. if (res.code === 0) {
  27. console.log(res.data)
  28. }
  29. })
  30. }
  31. const delCollection = (data) => {
  32. deleteCollection(data).then(res => {
  33. if (res.code === 0) {
  34. console.log(res.data)
  35. }
  36. })
  37. }
  38. return {
  39. paymentList,
  40. getPaymentList,
  41. postCollection,
  42. putCollection,
  43. delCollection
  44. }
  45. })