index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. export default {
  2. data() {
  3. return {
  4. loading: false,
  5. searchForm: {},
  6. pageInfo: {
  7. current: 1,
  8. size: 10,
  9. total: 0,
  10. },
  11. tableData: []
  12. }
  13. },
  14. mounted() {
  15. this.init()
  16. },
  17. onLoad({refresh}) {
  18. if(refresh === 'true' || refresh === true) {
  19. this.init()
  20. }
  21. },
  22. methods: {
  23. init() {
  24. this.getList()
  25. },
  26. search() {
  27. this.getList()
  28. },
  29. reset() {
  30. this.$refs.searchForm?.resetFields()
  31. this.getList()
  32. },
  33. getList() {
  34. this.loading = true
  35. this.tableData = []
  36. this.getListFun()({
  37. ...this.getConstantsQuery(),
  38. ...this.getQuery(),
  39. ...this.getPageInfo(),
  40. }).then(resp => {
  41. const list = this.parseList(resp)
  42. this.parsePageInfo(resp)
  43. this.tableData = list
  44. }).finally(_ => {
  45. this.loading = false
  46. })
  47. },
  48. parseList(resp) {
  49. return resp.data?.records || []
  50. },
  51. parsePageInfo(resp) {
  52. this.pageInfo = {
  53. current: resp.data.current,
  54. total: resp.data.total,
  55. size: resp.data.size,
  56. }
  57. },
  58. getConstantsQuery() {
  59. return {}
  60. },
  61. getQuery() {
  62. return this.searchForm
  63. },
  64. getPageInfo() {
  65. return this.pageInfo
  66. },
  67. getListFun() {
  68. return () => Promise.resolve([])
  69. },
  70. paginationChang({
  71. type,
  72. current
  73. }) {
  74. this.pageInfo.current = current
  75. this.getList()
  76. },
  77. view(data) {
  78. uni.navigateTo({
  79. url: `${this.editPath}?action=view&json=${JSON.stringify(data)}`
  80. })
  81. },
  82. edit(data) {
  83. uni.navigateTo({
  84. url: `${this.editPath}?action=edit&json=${JSON.stringify(data)}`
  85. })
  86. },
  87. isDelScucess(resp) {
  88. return resp.code === 200
  89. },
  90. getDelParam(data) {
  91. return data.id
  92. },
  93. del(data) {
  94. console.log('dele');
  95. uni.showModal({
  96. title: '提示',
  97. content: '确认删除吗?',
  98. success: (res) => {
  99. if(res.confirm) {
  100. this.getDelFun()(this.getDelParam(data)).then(resp => {
  101. if(this.isDelScucess(resp)) {
  102. this.getList()
  103. }else {
  104. }
  105. })
  106. }
  107. }
  108. })
  109. }
  110. }
  111. }