on.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // 开放接口
  2. import Status from "$mixins/status/const/status";
  3. import {FlatListReload} from "$components/flat-list/const";
  4. export default <LibMixins>{
  5. methods:{
  6. // 当前是否正在执行状态
  7. flat_is_loading(){
  8. return this._status === this.constStatus.loading;
  9. },
  10. flat_clear_to_start(){
  11. if (this.data.length > 0 || this.status!==this.constStatus.default) {
  12. // 控制为 无状态
  13. this.status = this.constStatus.default;
  14. this._status = this.constStatus.default;
  15. this.setStart(true);
  16. return this.setData([],true);
  17. }
  18. },
  19. flat_delete(id:number | string){
  20. id = this.flat_get_index(id);
  21. if (id >= 0) {
  22. this.data.splice(id,1);
  23. this.indexes && this.dataIndexes.splice(id,1);
  24. this.$emit('changeData',this.data);
  25. if (this.data.length <= 0) {
  26. return this.reload(FlatListReload.start);
  27. } else if (this.hasPaging && this.data.length < this.pageSize) {
  28. return this.reload(FlatListReload.next);
  29. }
  30. }
  31. },
  32. flat_update(id:number | string,item:Record<string, any>){
  33. id = this.flat_get_index(id);
  34. if (id >= 0) {
  35. this.data[id] = item;
  36. }
  37. },
  38. flat_get_data(id:number | string){
  39. return this.data[this.flat_get_index(id)]
  40. },
  41. flat_unshift(id:number | string,item:Record<string, any>){
  42. if (id) {
  43. if (this.start) {
  44. this.setStatus(Status.success,[item]);
  45. } else {
  46. if (this.indexes && this.dataIndexes.indexOf(id) >= 0) return;
  47. this.data.unshift(item);
  48. this.indexes && this.dataIndexes.unshift(id);
  49. return this.$emit('changeData',this.data);
  50. }
  51. }
  52. },
  53. flat_push(id:number | string,item:Record<string, any>){
  54. if (id) {
  55. if (this.start) {
  56. this.setStatus(Status.success,[item]);
  57. } else {
  58. if (this.indexes && this.dataIndexes.indexOf(id) >= 0) return;
  59. this.data.push(item);
  60. this.indexes && this.dataIndexes.push(id);
  61. return this.$emit('changeData',this.data);
  62. }
  63. }
  64. },
  65. flat_get_index(index:number | string){
  66. if (this.indexes) {
  67. let useIndex = this.dataIndexes && this.dataIndexes.indexOf(index);
  68. return useIndex === undefined ? -1 : useIndex;
  69. } else {
  70. return index;
  71. }
  72. }
  73. }
  74. }