RecordItem.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { View,Text } from "@tarojs/components";
  2. import React from "react";
  3. import './RecordItem.scss'
  4. import Taro from "@tarojs/taro";
  5. import { TimeFormatter } from "@/utils/time_format";
  6. export default function Component(props: { children: React.ReactNode,onClick?:Function, delete?: Function, canDel?: boolean }) {
  7. function click(e){
  8. if (props.onClick) {
  9. e.stopPropagation()
  10. props.onClick();
  11. }
  12. else {
  13. Taro.vibrateShort({
  14. type:'medium'
  15. });
  16. }
  17. }
  18. function longPress() {
  19. if (!props.delete) {
  20. return;
  21. }
  22. Taro.showActionSheet({
  23. itemList: ['删除']
  24. })
  25. .then(res => {
  26. switch (res.tapIndex) {
  27. case 0:
  28. Taro.showModal({
  29. title: '删除',
  30. content: '确认要删除吗?',
  31. success: function (res) {
  32. if (res.confirm) {
  33. props.delete!();
  34. }
  35. }
  36. })
  37. break;
  38. case 1:
  39. break;
  40. }
  41. })
  42. .catch(err => {
  43. console.log(err.errMsg)
  44. })
  45. }
  46. //gesture onClick onLongPress 有效
  47. return <View className="recordItem" onLongPress={longPress} onClick={click}>
  48. {props.children}
  49. </View>
  50. }