RecordItem.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. import { useTranslation } from "react-i18next";
  7. import { vibrate } from "@/utils/tools";
  8. export default function Component(props: { children: React.ReactNode, onClick?: Function, delete?: Function, canDel?: boolean }) {
  9. const { t } = useTranslation()
  10. function click(e) {
  11. if (props.onClick) {
  12. if (process.env.TARO_ENV == 'weapp') {
  13. e.stopPropagation()
  14. }
  15. props.onClick();
  16. }
  17. else {
  18. vibrate()
  19. }
  20. }
  21. function longPress() {
  22. if (!props.delete) {
  23. return;
  24. }
  25. Taro.showActionSheet({
  26. itemList: [t('feature.common.action_sheet.delete')],
  27. })
  28. .then(res => {
  29. switch (res.tapIndex) {
  30. case 0:
  31. Taro.showModal({
  32. title: t('feature.common.modal.delete_item_title'),
  33. content: t('feature.common.modal.delete_item_content'),
  34. success: function (res) {
  35. if (res.confirm) {
  36. props.delete!();
  37. }
  38. }
  39. })
  40. break;
  41. case 1:
  42. break;
  43. }
  44. })
  45. .catch(err => {
  46. console.log(err.errMsg)
  47. })
  48. }
  49. //gesture onClick onLongPress 有效
  50. return <View className="recordItem" onLongPress={longPress} onClick={click}>
  51. {props.children}
  52. </View>
  53. }