提交 6d34a5a9 编写于 作者: D DCloud_LXH

chore(h5): 1、toast 2、base.css add uni-loading

上级 cdfcda6a
...@@ -13123,13 +13123,16 @@ const props = { ...@@ -13123,13 +13123,16 @@ const props = {
type: Boolean type: Boolean
} }
}; };
const toastIconClassName = "uni-toast__icon";
var Toast = /* @__PURE__ */ defineComponent({ var Toast = /* @__PURE__ */ defineComponent({
name: "Toast", name: "Toast",
props, props,
setup(props2) { setup(props2) {
initI18nShowToastMsgsOnce();
initI18nShowLoadingMsgsOnce();
const { const {
iconClass Icon
} = useToastState(props2); } = useToastIcon(props2);
const visible = usePopup(props2, {}); const visible = usePopup(props2, {});
return () => { return () => {
const { const {
...@@ -13146,9 +13149,8 @@ var Toast = /* @__PURE__ */ defineComponent({ ...@@ -13146,9 +13149,8 @@ var Toast = /* @__PURE__ */ defineComponent({
}, [mask ? createVNode("div", { }, [mask ? createVNode("div", {
class: "uni-mask", class: "uni-mask",
style: "background: transparent;", style: "background: transparent;",
onTouchmove: withModifiers(() => { onTouchmove: onEventPrevent
}, ["prevent"]) }, null, 40, ["onTouchmove"]) : "", !image2 && !Icon.value ? createVNode("div", {
}, null, 40, ["onTouchmove"]) : "", !image2 && !iconClass ? createVNode("div", {
class: "uni-sample-toast" class: "uni-sample-toast"
}, [createVNode("p", { }, [createVNode("p", {
class: "uni-simple-toast__text" class: "uni-simple-toast__text"
...@@ -13156,20 +13158,22 @@ var Toast = /* @__PURE__ */ defineComponent({ ...@@ -13156,20 +13158,22 @@ var Toast = /* @__PURE__ */ defineComponent({
class: "uni-toast" class: "uni-toast"
}, [image2 ? createVNode("img", { }, [image2 ? createVNode("img", {
src: image2, src: image2,
class: "uni-toast__icon" class: toastIconClassName
}, null, 8, ["src"]) : createVNode("i", { }, null, 10, ["src"]) : Icon.value, createVNode("p", {
class: [iconClass, "uni-icon_toast"]
}, null, 2), createVNode("p", {
class: "uni-toast__content" class: "uni-toast__content"
}, [title])])], 8, ["data-duration"]), [[vShow, visible.value]])] }, [title])])], 8, ["data-duration"]), [[vShow, visible.value]])]
}); });
}; };
} }
}); });
function useToastState(props2) { function useToastIcon(props2) {
const iconClass = computed(() => props2.icon === "success" ? "uni-icon-success-no-circle" : props2.icon === "loading" ? "uni-loading" : ""); const Icon = computed(() => props2.icon === "success" ? createVNode(createSvgIconVNode(ICON_PATH_SUCCESS_NO_CIRCLE, "#fff", 38), {
class: toastIconClassName
}) : props2.icon === "loading" ? createVNode("i", {
class: [toastIconClassName, "uni-loading"]
}, null, 2) : null);
return { return {
iconClass Icon
}; };
} }
let showToastState; let showToastState;
...@@ -13194,11 +13198,12 @@ function createToast(args) { ...@@ -13194,11 +13198,12 @@ function createToast(args) {
timeoutId = setTimeout(() => { timeoutId = setTimeout(() => {
hidePopup("onHideToast"); hidePopup("onHideToast");
}, showToastState.duration); }, showToastState.duration);
} else {
timeoutId && clearTimeout(timeoutId);
} }
}); });
} }
const showToast = defineAsyncApi(API_SHOW_TOAST, (args, {resolve, reject}) => { const showToast = defineAsyncApi(API_SHOW_TOAST, (args, {resolve, reject}) => {
initI18nShowToastMsgsOnce();
createToast(args); createToast(args);
showType = "onShowToast"; showType = "onShowToast";
resolve(); resolve();
...@@ -13210,7 +13215,6 @@ const showLoadingDefaultState = { ...@@ -13210,7 +13215,6 @@ const showLoadingDefaultState = {
}; };
const showLoading = defineAsyncApi(API_SHOW_LOADING, (args, {resolve, reject}) => { const showLoading = defineAsyncApi(API_SHOW_LOADING, (args, {resolve, reject}) => {
extend(args, showLoadingDefaultState); extend(args, showLoadingDefaultState);
initI18nShowLoadingMsgsOnce();
createToast(args); createToast(args);
showType = "onShowLoading"; showType = "onShowLoading";
resolve(); resolve();
......
//#region Functions
import { reactive, nextTick, watchEffect } from 'vue' import { reactive, nextTick, watchEffect } from 'vue'
import { extend } from '@vue/shared' import { extend } from '@vue/shared'
import { import {
...@@ -13,18 +14,17 @@ import { ...@@ -13,18 +14,17 @@ import {
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
import Toast, { ToastProps } from './toast' import Toast, { ToastProps } from './toast'
import { ensureRoot, createRootApp } from './utils' import { ensureRoot, createRootApp } from './utils'
import { import { useI18n } from '@dcloudio/uni-core'
useI18n, //#endregion
initI18nShowLoadingMsgsOnce,
initI18nShowToastMsgsOnce,
} from '@dcloudio/uni-core'
//#region Type
import type { import type {
API_TYPE_SHOW_LOADING, API_TYPE_SHOW_LOADING,
API_TYPE_HIDE_TOAST, API_TYPE_HIDE_TOAST,
API_TYPE_HIDE_LOADING, API_TYPE_HIDE_LOADING,
API_TYPE_SHOW_TOAST, API_TYPE_SHOW_TOAST,
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
//#endregion
let showToastState: ToastProps let showToastState: ToastProps
let showType: 'onShowToast' | 'onShowLoading' | '' = '' let showType: 'onShowToast' | 'onShowLoading' | '' = ''
...@@ -52,6 +52,8 @@ function createToast(args: ToastProps) { ...@@ -52,6 +52,8 @@ function createToast(args: ToastProps) {
timeoutId = setTimeout(() => { timeoutId = setTimeout(() => {
hidePopup('onHideToast') hidePopup('onHideToast')
}, showToastState.duration) }, showToastState.duration)
} else {
timeoutId && clearTimeout(timeoutId)
} }
}) })
} }
...@@ -59,7 +61,6 @@ function createToast(args: ToastProps) { ...@@ -59,7 +61,6 @@ function createToast(args: ToastProps) {
export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>( export const showToast = defineAsyncApi<API_TYPE_SHOW_TOAST>(
API_SHOW_TOAST, API_SHOW_TOAST,
(args, { resolve, reject }) => { (args, { resolve, reject }) => {
initI18nShowToastMsgsOnce()
createToast(args as ToastProps) createToast(args as ToastProps)
showType = 'onShowToast' showType = 'onShowToast'
resolve() resolve()
...@@ -78,7 +79,6 @@ export const showLoading = defineAsyncApi<API_TYPE_SHOW_LOADING>( ...@@ -78,7 +79,6 @@ export const showLoading = defineAsyncApi<API_TYPE_SHOW_LOADING>(
API_SHOW_LOADING, API_SHOW_LOADING,
(args, { resolve, reject }) => { (args, { resolve, reject }) => {
extend(args, showLoadingDefaultState) extend(args, showLoadingDefaultState)
initI18nShowLoadingMsgsOnce()
createToast(args as ToastProps) createToast(args as ToastProps)
showType = 'onShowLoading' showType = 'onShowLoading'
resolve() resolve()
......
...@@ -2,12 +2,21 @@ import { ...@@ -2,12 +2,21 @@ import {
Transition, Transition,
defineComponent, defineComponent,
ExtractPropTypes, ExtractPropTypes,
withModifiers,
computed, computed,
createVNode,
} from 'vue' } from 'vue'
import { SHOW_TOAST_ICON } from '@dcloudio/uni-api' import { SHOW_TOAST_ICON } from '@dcloudio/uni-api'
import type { API_TYPE_SHOW_TOAST_ICON } from '@dcloudio/uni-api' import type { API_TYPE_SHOW_TOAST_ICON } from '@dcloudio/uni-api'
import { usePopup } from './utils' import { usePopup } from './utils'
import {
onEventPrevent,
createSvgIconVNode,
ICON_PATH_SUCCESS_NO_CIRCLE,
} from '@dcloudio/uni-core'
import {
initI18nShowToastMsgsOnce,
initI18nShowLoadingMsgsOnce,
} from '@dcloudio/uni-core'
const props = { const props = {
title: { title: {
...@@ -36,6 +45,7 @@ const props = { ...@@ -36,6 +45,7 @@ const props = {
type: Boolean, type: Boolean,
}, },
} }
const ToastIconClassName = 'uni-toast__icon'
export type ToastProps = ExtractPropTypes<typeof props> export type ToastProps = ExtractPropTypes<typeof props>
...@@ -43,7 +53,9 @@ export default /*#__PURE__*/ defineComponent({ ...@@ -43,7 +53,9 @@ export default /*#__PURE__*/ defineComponent({
name: 'Toast', name: 'Toast',
props, props,
setup(props) { setup(props) {
const { iconClass } = useToastState(props) initI18nShowToastMsgsOnce()
initI18nShowLoadingMsgsOnce()
const { Icon } = useToastIcon(props)
const visible = usePopup(props, {}) const visible = usePopup(props, {})
return () => { return () => {
...@@ -55,21 +67,21 @@ export default /*#__PURE__*/ defineComponent({ ...@@ -55,21 +67,21 @@ export default /*#__PURE__*/ defineComponent({
<div <div
class="uni-mask" class="uni-mask"
style="background: transparent;" style="background: transparent;"
onTouchmove={withModifiers(() => {}, ['prevent'])} onTouchmove={onEventPrevent}
/> />
) : ( ) : (
'' ''
)} )}
{!image && !iconClass ? ( {!image && !Icon.value ? (
<div class="uni-sample-toast"> <div class="uni-sample-toast">
<p class="uni-simple-toast__text">{title}</p> <p class="uni-simple-toast__text">{title}</p>
</div> </div>
) : ( ) : (
<div class="uni-toast"> <div class="uni-toast">
{image ? ( {image ? (
<img src={image} class="uni-toast__icon" /> <img src={image} class={ToastIconClassName} />
) : ( ) : (
<i class={iconClass} class="uni-icon_toast" /> Icon.value
)} )}
<p class="uni-toast__content">{title}</p> <p class="uni-toast__content">{title}</p>
</div> </div>
...@@ -81,16 +93,18 @@ export default /*#__PURE__*/ defineComponent({ ...@@ -81,16 +93,18 @@ export default /*#__PURE__*/ defineComponent({
}, },
}) })
function useToastState(props: ToastProps) { function useToastIcon(props: ToastProps) {
const iconClass = computed(() => const Icon = computed(() =>
props.icon === 'success' props.icon === 'success' ? (
? 'uni-icon-success-no-circle' createVNode(createSvgIconVNode(ICON_PATH_SUCCESS_NO_CIRCLE, '#fff', 38), {
: props.icon === 'loading' class: ToastIconClassName,
? 'uni-loading' })
: '' ) : props.icon === 'loading' ? (
<i class={ToastIconClassName} class="uni-loading"></i>
) : null
) )
return { return {
iconClass, Icon,
} }
} }
...@@ -52,3 +52,29 @@ uni-page-wrapper { ...@@ -52,3 +52,29 @@ uni-page-wrapper {
.uni-fade-leave-active { .uni-fade-leave-active {
opacity: 0; opacity: 0;
} }
.uni-loading,
uni-button[loading]:before {
background: transparent
url('data:image/svg+xml;base64, PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iMTIwIiB2aWV3Qm94PSIwIDAgMTAwIDEwMCI+PHBhdGggZmlsbD0ibm9uZSIgZD0iTTAgMGgxMDB2MTAwSDB6Ii8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTlFOUU5IiByeD0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0NS45OCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDQkNCQ0IiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTEyMCA0MS4zNCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNEMkQyRDIiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTkwIDM1IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0RBREFEQSIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgtNjAgMjQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTJFMkUyIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKC0zMCAtNS45OCA2NSkiLz48L3N2Zz4=')
no-repeat;
}
.uni-loading {
width: 20px;
height: 20px;
display: inline-block;
vertical-align: middle;
animation: uni-loading 1s steps(12, end) infinite;
background-size: 100%;
}
@keyframes uni-loading {
0% {
transform: rotate3d(0, 0, 1, 0deg);
}
100% {
transform: rotate3d(0, 0, 1, 360deg);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册