RecordItem.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. import showActionSheet from "@/components/basic/ActionSheet";
  9. import showAlert from "@/components/basic/Alert";
  10. let useActionSheet;
  11. if (process.env.TARO_ENV == 'rn') {
  12. useActionSheet = require('@expo/react-native-action-sheet').useActionSheet
  13. }
  14. export default function Component(props: { children: React.ReactNode, onClick?: Function, delete?: Function, canDel?: boolean, disableDelete?: boolean }) {
  15. const { t } = useTranslation()
  16. let showActionSheetWithOptions;
  17. if (process.env.TARO_ENV == 'rn') {
  18. showActionSheetWithOptions = useActionSheet()
  19. }
  20. function click(e) {
  21. if (props.onClick) {
  22. if (process.env.TARO_ENV == 'weapp') {
  23. e.stopPropagation()
  24. }
  25. props.onClick();
  26. }
  27. else {
  28. vibrate()
  29. }
  30. }
  31. function longPress() {
  32. if (global.dimissSel){
  33. global.dimissSel()
  34. }
  35. console.log(props.disableDelete)
  36. if (!props.delete || props.disableDelete) {
  37. return;
  38. }
  39. showActionSheet({
  40. showActionSheetWithOptions: showActionSheetWithOptions,
  41. itemList: [t('feature.common.action_sheet.delete')],
  42. success: (res) => {
  43. switch (res) {
  44. case 0:
  45. {
  46. showAlert({
  47. title: t('feature.common.modal.delete_item_title'),
  48. content: t('feature.common.modal.delete_item_content'),
  49. showCancel: true,
  50. confirm: () => {
  51. props.delete!();
  52. }
  53. })
  54. }
  55. break;
  56. }
  57. }
  58. })
  59. // Taro.showActionSheet({
  60. // itemList: [t('feature.common.action_sheet.delete')],
  61. // itemColor: '#ff0000'
  62. // })
  63. // .then(res => {
  64. // switch (res.tapIndex) {
  65. // case 0:
  66. // showAlert({
  67. // title: t('feature.common.modal.delete_item_title'),
  68. // content: t('feature.common.modal.delete_item_content'),
  69. // showCancel: true,
  70. // confirm: () => {
  71. // props.delete!();
  72. // }
  73. // })
  74. // break;
  75. // case 1:
  76. // break;
  77. // }
  78. // })
  79. // .catch(err => {
  80. // })
  81. }
  82. //gesture onClick onLongPress 有效
  83. return <View className="recordItem" onLongPress={longPress} onClick={click}>
  84. {props.children}
  85. </View>
  86. }