action-sheet.uvue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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] !rounded-xl'
  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 flex flex-row items-center">
  46. <cl-checkbox v-model="agree">请阅读并同意</cl-checkbox>
  47. <cl-text color="primary">《会员服务协议》</cl-text>
  48. </view>
  49. </template>
  50. <template #item="{ item }">
  51. <view class="flex flex-col justify-center items-center">
  52. <cl-icon :name="item.icon" :size="46"></cl-icon>
  53. <cl-text :pt="{ className: '!text-sm mt-1' }">{{ item.label }}</cl-text>
  54. </view>
  55. </template>
  56. </cl-action-sheet>
  57. </cl-page>
  58. </template>
  59. <script lang="ts" setup>
  60. import { t } from "@/locale";
  61. import DemoItem from "../components/item.uvue";
  62. import { ref } from "vue";
  63. import { useUi, type ClActionSheetOptions } from "@/uni_modules/cool-ui";
  64. const ui = useUi();
  65. const actionSheetRef = ref<ClActionSheetComponentPublicInstance | null>(null);
  66. function openActionSheet() {
  67. actionSheetRef.value!.open({
  68. list: [
  69. {
  70. label: t("反馈")
  71. }
  72. ]
  73. } as ClActionSheetOptions);
  74. }
  75. const actionSheetRef2 = ref<ClActionSheetComponentPublicInstance | null>(null);
  76. function openActionSheet2() {
  77. actionSheetRef.value!.open({
  78. list: [
  79. {
  80. label: t("反馈"),
  81. icon: "error-warning-line"
  82. }
  83. ]
  84. } as ClActionSheetOptions);
  85. }
  86. const actionSheetRef3 = ref<ClActionSheetComponentPublicInstance | null>(null);
  87. function openActionSheet3() {
  88. actionSheetRef.value!.open({
  89. title: t("提示"),
  90. description: t("删除好友会同时删除所有聊天记录"),
  91. list: [
  92. {
  93. label: t("删除好友"),
  94. color: "error",
  95. callback() {
  96. ui.showConfirm({
  97. title: t("提示"),
  98. message: t("确定要删除好友吗?"),
  99. callback(action) {
  100. if (action == "confirm") {
  101. ui.showToast({
  102. message: t("删除成功")
  103. });
  104. }
  105. actionSheetRef.value!.close();
  106. }
  107. });
  108. }
  109. }
  110. ]
  111. } as ClActionSheetOptions);
  112. }
  113. const actionSheetRef4 = ref<ClActionSheetComponentPublicInstance | null>(null);
  114. function openActionSheet4() {
  115. actionSheetRef.value!.open({
  116. maskClosable: false,
  117. description: t("无法点击遮罩关闭"),
  118. list: []
  119. } as ClActionSheetOptions);
  120. }
  121. const actionSheetRef5 = ref<ClActionSheetComponentPublicInstance | null>(null);
  122. function openActionSheet5() {
  123. actionSheetRef.value!.open({
  124. showCancel: false,
  125. list: [
  126. {
  127. label: t("点我关闭"),
  128. callback() {
  129. ui.showConfirm({
  130. title: t("提示"),
  131. message: t("确定要关闭吗?"),
  132. callback(action) {
  133. if (action == "confirm") {
  134. actionSheetRef.value!.close();
  135. }
  136. }
  137. });
  138. }
  139. }
  140. ]
  141. } as ClActionSheetOptions);
  142. }
  143. const agree = ref(false);
  144. const actionSheetRef6 = ref<ClActionSheetComponentPublicInstance | null>(null);
  145. function openActionSheet6() {
  146. function done() {
  147. if (!agree.value) {
  148. ui.showToast({
  149. message: "请阅读并同意《会员服务协议》"
  150. });
  151. return;
  152. }
  153. ui.showToast({
  154. message: t("支付成功")
  155. });
  156. agree.value = false;
  157. actionSheetRef6.value!.close();
  158. }
  159. actionSheetRef6.value!.open({
  160. showCancel: false,
  161. list: [
  162. {
  163. label: t("支付宝"),
  164. icon: "alipay-line",
  165. callback() {
  166. done();
  167. }
  168. },
  169. {
  170. label: t("微信"),
  171. icon: "wechat-line",
  172. callback() {
  173. done();
  174. }
  175. }
  176. ]
  177. } as ClActionSheetOptions);
  178. }
  179. </script>