action-sheet.uvue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('基础用法')">
  5. <cl-button @tap="openActionSheet">{{ t("打开") }}</cl-button>
  6. </demo-item>
  7. <demo-item :label="t('带图标')">
  8. <cl-button @tap="openActionSheet2">{{ t("打开") }}</cl-button>
  9. </demo-item>
  10. <demo-item :label="t('带标题、描述')">
  11. <cl-button @tap="openActionSheet3">{{ t("打开") }}</cl-button>
  12. </demo-item>
  13. <demo-item :label="t('无法点击遮罩关闭')">
  14. <cl-button @tap="openActionSheet4">{{ t("打开") }}</cl-button>
  15. </demo-item>
  16. <demo-item :label="t('不需要取消按钮')">
  17. <cl-button @tap="openActionSheet5">{{ t("打开") }}</cl-button>
  18. </demo-item>
  19. <demo-item :label="t('插槽用法')">
  20. <cl-button @tap="openActionSheet6">{{ t("打开") }}</cl-button>
  21. </demo-item>
  22. </view>
  23. <cl-action-sheet ref="actionSheetRef"> </cl-action-sheet>
  24. <cl-action-sheet ref="actionSheetRef2"> </cl-action-sheet>
  25. <cl-action-sheet ref="actionSheetRef3"> </cl-action-sheet>
  26. <cl-action-sheet ref="actionSheetRef4"> </cl-action-sheet>
  27. <cl-action-sheet ref="actionSheetRef5"> </cl-action-sheet>
  28. <cl-action-sheet
  29. ref="actionSheetRef6"
  30. :pt="{
  31. list: {
  32. className: 'flex-row mx-[-10rpx]'
  33. },
  34. item: {
  35. className: 'flex-1 mx-[10rpx]'
  36. }
  37. }"
  38. >
  39. <template #prepend>
  40. <view class="px-3 mb-3">
  41. <cl-text>开通会员享受更多特权和服务,包括无广告体验、专属客服等</cl-text>
  42. </view>
  43. </template>
  44. <template #append>
  45. <view class="pb-5 pt-2 px-3">
  46. <cl-checkbox v-model="agree"
  47. >请阅读并同意《会员服务协议》和《隐私政策》</cl-checkbox
  48. >
  49. </view>
  50. </template>
  51. <template #item="{ item }">
  52. <view class="flex flex-col justify-center items-center">
  53. <cl-icon :name="item.icon" :size="46"></cl-icon>
  54. <cl-text :pt="{ className: '!text-sm mt-1' }">{{ item.label }}</cl-text>
  55. </view>
  56. </template>
  57. </cl-action-sheet>
  58. </cl-page>
  59. </template>
  60. <script lang="ts" setup>
  61. import { t } from "@/locale";
  62. import DemoItem from "../components/item.uvue";
  63. import { ref } from "vue";
  64. import { useUi, type ClActionSheetOptions } from "@/uni_modules/cool-ui";
  65. const ui = useUi();
  66. const actionSheetRef = ref<ClActionSheetComponentPublicInstance | null>(null);
  67. function openActionSheet() {
  68. actionSheetRef.value!.open({
  69. list: [
  70. {
  71. label: t("反馈")
  72. }
  73. ]
  74. } as ClActionSheetOptions);
  75. }
  76. const actionSheetRef2 = ref<ClActionSheetComponentPublicInstance | null>(null);
  77. function openActionSheet2() {
  78. actionSheetRef.value!.open({
  79. list: [
  80. {
  81. label: t("反馈"),
  82. icon: "error-warning-line"
  83. }
  84. ]
  85. } as ClActionSheetOptions);
  86. }
  87. const actionSheetRef3 = ref<ClActionSheetComponentPublicInstance | null>(null);
  88. function openActionSheet3() {
  89. actionSheetRef.value!.open({
  90. title: t("提示"),
  91. description: t("删除好友会同时删除所有聊天记录"),
  92. list: [
  93. {
  94. label: t("删除好友"),
  95. color: "error",
  96. callback() {
  97. ui.showConfirm({
  98. title: t("提示"),
  99. message: t("确定要删除好友吗?"),
  100. callback(action) {
  101. if (action == "confirm") {
  102. ui.showToast({
  103. message: t("删除成功")
  104. });
  105. }
  106. actionSheetRef.value!.close();
  107. }
  108. });
  109. }
  110. }
  111. ]
  112. } as ClActionSheetOptions);
  113. }
  114. const actionSheetRef4 = ref<ClActionSheetComponentPublicInstance | null>(null);
  115. function openActionSheet4() {
  116. actionSheetRef.value!.open({
  117. maskClosable: false,
  118. description: t("无法点击遮罩关闭"),
  119. list: []
  120. } as ClActionSheetOptions);
  121. }
  122. const actionSheetRef5 = ref<ClActionSheetComponentPublicInstance | null>(null);
  123. function openActionSheet5() {
  124. actionSheetRef.value!.open({
  125. showCancel: false,
  126. list: [
  127. {
  128. label: t("点我关闭"),
  129. callback() {
  130. ui.showConfirm({
  131. title: t("提示"),
  132. message: t("确定要关闭吗?"),
  133. callback(action) {
  134. if (action == "confirm") {
  135. actionSheetRef.value!.close();
  136. }
  137. }
  138. });
  139. }
  140. }
  141. ]
  142. } as ClActionSheetOptions);
  143. }
  144. const agree = ref(false);
  145. const actionSheetRef6 = ref<ClActionSheetComponentPublicInstance | null>(null);
  146. function openActionSheet6() {
  147. function done() {
  148. if (!agree.value) {
  149. ui.showToast({
  150. message: t("请阅读并同意《会员服务协议》和《隐私政策》")
  151. });
  152. return;
  153. }
  154. ui.showToast({
  155. message: t("支付成功")
  156. });
  157. agree.value = false;
  158. actionSheetRef6.value!.close();
  159. }
  160. actionSheetRef6.value!.open({
  161. showCancel: false,
  162. list: [
  163. {
  164. label: t("支付宝"),
  165. icon: "alipay-line",
  166. callback() {
  167. done();
  168. }
  169. },
  170. {
  171. label: t("微信"),
  172. icon: "wechat-line",
  173. callback() {
  174. done();
  175. }
  176. }
  177. ]
  178. } as ClActionSheetOptions);
  179. }
  180. </script>