action-sheet.uvue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 ref="actionSheetRef6">
  29. <template #prepend>
  30. <view class="px-3 mb-3">
  31. <cl-text>开通会员享受更多特权和服务,包括无广告体验、专属客服等</cl-text>
  32. </view>
  33. </template>
  34. <template #append>
  35. <view class="pb-5 pt-2 px-3">
  36. <cl-checkbox v-model="agree">
  37. 请阅读并同意《会员服务协议》和《隐私政策》
  38. </cl-checkbox>
  39. </view>
  40. </template>
  41. </cl-action-sheet>
  42. </cl-page>
  43. </template>
  44. <script lang="ts" setup>
  45. import { t } from "@/locale";
  46. import DemoItem from "../components/item.uvue";
  47. import { ref } from "vue";
  48. import { useUi, type ClActionSheetOptions } from "@/uni_modules/cool-ui";
  49. const ui = useUi();
  50. const actionSheetRef = ref<ClActionSheetComponentPublicInstance | null>(null);
  51. function openActionSheet() {
  52. actionSheetRef.value!.open({
  53. list: [
  54. {
  55. label: t("反馈")
  56. }
  57. ]
  58. } as ClActionSheetOptions);
  59. }
  60. const actionSheetRef2 = ref<ClActionSheetComponentPublicInstance | null>(null);
  61. function openActionSheet2() {
  62. actionSheetRef.value!.open({
  63. list: [
  64. {
  65. label: t("反馈"),
  66. icon: "feedback-line"
  67. }
  68. ]
  69. } as ClActionSheetOptions);
  70. }
  71. const actionSheetRef3 = ref<ClActionSheetComponentPublicInstance | null>(null);
  72. function openActionSheet3() {
  73. actionSheetRef.value!.open({
  74. title: t("提示"),
  75. description: t("删除好友会同时删除所有聊天记录"),
  76. list: [
  77. {
  78. label: t("删除好友"),
  79. color: "error",
  80. callback() {
  81. ui.showConfirm({
  82. title: t("提示"),
  83. message: t("确定要删除好友吗?"),
  84. callback(action) {
  85. if (action == "confirm") {
  86. ui.showToast({
  87. message: t("删除成功")
  88. });
  89. }
  90. actionSheetRef.value!.close();
  91. }
  92. });
  93. }
  94. }
  95. ]
  96. } as ClActionSheetOptions);
  97. }
  98. const actionSheetRef4 = ref<ClActionSheetComponentPublicInstance | null>(null);
  99. function openActionSheet4() {
  100. actionSheetRef.value!.open({
  101. maskClosable: false,
  102. description: t("无法点击遮罩关闭"),
  103. list: []
  104. } as ClActionSheetOptions);
  105. }
  106. const actionSheetRef5 = ref<ClActionSheetComponentPublicInstance | null>(null);
  107. function openActionSheet5() {
  108. actionSheetRef.value!.open({
  109. showCancel: false,
  110. list: [
  111. {
  112. label: t("点我关闭"),
  113. callback() {
  114. ui.showConfirm({
  115. title: t("提示"),
  116. message: t("确定要关闭吗?"),
  117. callback(action) {
  118. if (action == "confirm") {
  119. actionSheetRef.value!.close();
  120. }
  121. }
  122. });
  123. }
  124. }
  125. ]
  126. } as ClActionSheetOptions);
  127. }
  128. const agree = ref(false);
  129. const actionSheetRef6 = ref<ClActionSheetComponentPublicInstance | null>(null);
  130. function openActionSheet6() {
  131. function done() {
  132. if (!agree.value) {
  133. ui.showToast({
  134. message: t("请阅读并同意《会员服务协议》和《隐私政策》")
  135. });
  136. return;
  137. }
  138. ui.showToast({
  139. message: t("支付成功")
  140. });
  141. agree.value = false;
  142. actionSheetRef6.value!.close();
  143. }
  144. actionSheetRef6.value!.open({
  145. showCancel: false,
  146. list: [
  147. {
  148. label: t("支付宝"),
  149. icon: "alipay-line",
  150. callback() {
  151. done();
  152. }
  153. },
  154. {
  155. label: t("微信"),
  156. icon: "wechat-line",
  157. callback() {
  158. done();
  159. }
  160. }
  161. ]
  162. } as ClActionSheetOptions);
  163. }
  164. </script>