From 026cf64a3b916ca764a3877fab0ba9890435abd9 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 22 Apr 2021 15:39:51 +0800 Subject: [PATCH] refactor: popup --- packages/uni-api/src/index.ts | 9 +- .../uni-api/src/protocols/ui/hideLoading.ts | 2 + .../uni-api/src/protocols/ui/hideToast.ts | 2 + packages/uni-api/src/protocols/ui/popup.ts | 100 ------------------ .../src/protocols/ui/showActionSheet.ts | 14 +++ .../uni-api/src/protocols/ui/showLoading.ts | 12 +++ .../uni-api/src/protocols/ui/showModal.ts | 42 ++++++++ .../uni-api/src/protocols/ui/showToast.ts | 28 +++++ packages/uni-h5/dist/uni-h5.esm.js | 89 ++++++++-------- 9 files changed, 151 insertions(+), 147 deletions(-) create mode 100644 packages/uni-api/src/protocols/ui/hideLoading.ts create mode 100644 packages/uni-api/src/protocols/ui/hideToast.ts delete mode 100644 packages/uni-api/src/protocols/ui/popup.ts create mode 100644 packages/uni-api/src/protocols/ui/showActionSheet.ts create mode 100644 packages/uni-api/src/protocols/ui/showLoading.ts create mode 100644 packages/uni-api/src/protocols/ui/showModal.ts create mode 100644 packages/uni-api/src/protocols/ui/showToast.ts diff --git a/packages/uni-api/src/index.ts b/packages/uni-api/src/index.ts index 580a09787..63cb40ef8 100644 --- a/packages/uni-api/src/index.ts +++ b/packages/uni-api/src/index.ts @@ -45,10 +45,15 @@ export * from './protocols/location/getLocation' export * from './protocols/route/route' +export * from './protocols/ui/hideLoading' +export * from './protocols/ui/hideToast' export * from './protocols/ui/loadFontFace' -export * from './protocols/ui/pageScrollTo' export * from './protocols/ui/navigationBar' -export * from './protocols/ui/popup' +export * from './protocols/ui/pageScrollTo' +export * from './protocols/ui/showActionSheet' +export * from './protocols/ui/showLoading' +export * from './protocols/ui/showModal' +export * from './protocols/ui/showToast' export * from './protocols/ui/startPullDownRefresh' export * from './protocols/ui/stopPullDownRefresh' export * from './protocols/ui/tabBar' diff --git a/packages/uni-api/src/protocols/ui/hideLoading.ts b/packages/uni-api/src/protocols/ui/hideLoading.ts new file mode 100644 index 000000000..a7add4583 --- /dev/null +++ b/packages/uni-api/src/protocols/ui/hideLoading.ts @@ -0,0 +1,2 @@ +export const API_HIDE_LOADING = 'hideLoading' +export type API_TYPE_HIDE_LOADING = typeof uni.hideLoading diff --git a/packages/uni-api/src/protocols/ui/hideToast.ts b/packages/uni-api/src/protocols/ui/hideToast.ts new file mode 100644 index 000000000..fd53c7a85 --- /dev/null +++ b/packages/uni-api/src/protocols/ui/hideToast.ts @@ -0,0 +1,2 @@ +export const API_HIDE_TOAST = 'hideToast' +export type API_TYPE_HIDE_TOAST = typeof uni.hideToast diff --git a/packages/uni-api/src/protocols/ui/popup.ts b/packages/uni-api/src/protocols/ui/popup.ts deleted file mode 100644 index cceb665c7..000000000 --- a/packages/uni-api/src/protocols/ui/popup.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { hasOwn } from '@vue/shared' -import { useI18n, initI18nShowModalMsgsOnce } from '@dcloudio/uni-core' -import { PRIMARY_COLOR } from '@dcloudio//uni-shared' -import { getRealPath } from '@dcloudio/uni-platform' -export const API_SHOW_MODAL = 'showModal' -export type API_TYPE_SHOW_MODAL = typeof uni.showModal - -export const ShowModalProtocol: ApiProtocol = { - title: String, - content: String, - showCancel: Boolean, - cancelText: String, - cancelColor: String, - confirmText: String, - confirmColor: String, -} - -export const ShowModalOptions: ApiOptions = { - beforeInvoke() { - // dynamic init (tree shaking) - initI18nShowModalMsgsOnce() - }, - formatArgs: { - title: '', - content: '', - showCancel: true, - cancelText(_value, params) { - if (!hasOwn(params, 'cancelText')) { - const { t } = useI18n() - params.cancelText = t('uni.showModal.cancel') - } - }, - cancelColor: '#000', - confirmText(_value, params) { - if (!hasOwn(params, 'confirmText')) { - const { t } = useI18n() - params.confirmText = t('uni.showModal.confirm') - } - }, - confirmColor: PRIMARY_COLOR, - }, -} -export const API_SHOW_TOAST = 'showToast' -export type API_TYPE_SHOW_TOAST = typeof uni.showToast -export const ShowToastProtocol: ApiProtocol = { - title: String, - icon: String as any, - image: String, - duration: Number, - mask: Boolean, -} -export const ShowToastOptions: ApiOptions = { - formatArgs: { - title: '', - icon(value, params) { - if (['success', 'loading', 'none'].indexOf(value!) === -1) { - params.icon = 'success' - } - }, - image(value, params) { - if (value) { - params.image = getRealPath(value) - } - }, - duration: 1500, - mask: false, - }, -} -export const API_SHOW_LOADING = 'showLoading' -export type API_TYPE_SHOW_LOADING = typeof uni.showLoading -export const ShowLoadingProtocol: ApiProtocol = { - title: String, - mask: Boolean, -} -export const ShowLoadingOptions: ApiOptions = { - formatArgs: { - title: '', - mask: false, - }, -} - -export const API_SHOW_ACTION_SHEET = 'showActionSheet' -export type API_TYPE_SHOW_ACTION_SHEET = typeof uni.showActionSheet -export const ShowActionSheetProtocol: ApiProtocol = { - itemList: { - type: Array, - required: true, - }, - itemColor: String, -} -export const ShowActionSheetOptions: ApiOptions = { - formatArgs: { - itemColor: '#000', - }, -} - -export const API_HIDE_TOAST = 'hideToast' -export type API_TYPE_HIDE_TOAST = typeof uni.hideToast -export const API_HIDE_LOADING = 'hideLoading' -export type API_TYPE_HIDE_LOADING = typeof uni.hideLoading diff --git a/packages/uni-api/src/protocols/ui/showActionSheet.ts b/packages/uni-api/src/protocols/ui/showActionSheet.ts new file mode 100644 index 000000000..9c034d6ea --- /dev/null +++ b/packages/uni-api/src/protocols/ui/showActionSheet.ts @@ -0,0 +1,14 @@ +export const API_SHOW_ACTION_SHEET = 'showActionSheet' +export type API_TYPE_SHOW_ACTION_SHEET = typeof uni.showActionSheet +export const ShowActionSheetProtocol: ApiProtocol = { + itemList: { + type: Array, + required: true, + }, + itemColor: String, +} +export const ShowActionSheetOptions: ApiOptions = { + formatArgs: { + itemColor: '#000', + }, +} diff --git a/packages/uni-api/src/protocols/ui/showLoading.ts b/packages/uni-api/src/protocols/ui/showLoading.ts new file mode 100644 index 000000000..31da86b9c --- /dev/null +++ b/packages/uni-api/src/protocols/ui/showLoading.ts @@ -0,0 +1,12 @@ +export const API_SHOW_LOADING = 'showLoading' +export type API_TYPE_SHOW_LOADING = typeof uni.showLoading +export const ShowLoadingProtocol: ApiProtocol = { + title: String, + mask: Boolean, +} +export const ShowLoadingOptions: ApiOptions = { + formatArgs: { + title: '', + mask: false, + }, +} diff --git a/packages/uni-api/src/protocols/ui/showModal.ts b/packages/uni-api/src/protocols/ui/showModal.ts new file mode 100644 index 000000000..d01202470 --- /dev/null +++ b/packages/uni-api/src/protocols/ui/showModal.ts @@ -0,0 +1,42 @@ +import { hasOwn } from '@vue/shared' +import { PRIMARY_COLOR } from '@dcloudio/uni-shared' +import { initI18nShowModalMsgsOnce, useI18n } from '@dcloudio/uni-core' + +export const API_SHOW_MODAL = 'showModal' +export type API_TYPE_SHOW_MODAL = typeof uni.showModal + +export const ShowModalProtocol: ApiProtocol = { + title: String, + content: String, + showCancel: Boolean, + cancelText: String, + cancelColor: String, + confirmText: String, + confirmColor: String, +} + +export const ShowModalOptions: ApiOptions = { + beforeInvoke() { + // dynamic init (tree shaking) + initI18nShowModalMsgsOnce() + }, + formatArgs: { + title: '', + content: '', + showCancel: true, + cancelText(_value, params) { + if (!hasOwn(params, 'cancelText')) { + const { t } = useI18n() + params.cancelText = t('uni.showModal.cancel') + } + }, + cancelColor: '#000', + confirmText(_value, params) { + if (!hasOwn(params, 'confirmText')) { + const { t } = useI18n() + params.confirmText = t('uni.showModal.confirm') + } + }, + confirmColor: PRIMARY_COLOR, + }, +} diff --git a/packages/uni-api/src/protocols/ui/showToast.ts b/packages/uni-api/src/protocols/ui/showToast.ts new file mode 100644 index 000000000..1e0e6a663 --- /dev/null +++ b/packages/uni-api/src/protocols/ui/showToast.ts @@ -0,0 +1,28 @@ +import { getRealPath } from '@dcloudio/uni-platform' + +export const API_SHOW_TOAST = 'showToast' +export type API_TYPE_SHOW_TOAST = typeof uni.showToast +export const ShowToastProtocol: ApiProtocol = { + title: String, + icon: String as any, + image: String, + duration: Number, + mask: Boolean, +} +export const ShowToastOptions: ApiOptions = { + formatArgs: { + title: '', + icon(value, params) { + if (['success', 'loading', 'none'].indexOf(value!) === -1) { + params.icon = 'success' + } + }, + image(value, params) { + if (value) { + params.image = getRealPath(value) + } + }, + duration: 1500, + mask: false, + }, +} diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index 8fa24dd89..8b642bba1 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -1,6 +1,6 @@ import {isFunction, extend, isPlainObject, isString, isArray, hasOwn as hasOwn$1, isObject as isObject$1, capitalize, toRawType, makeMap as makeMap$1, isPromise, invokeArrayFns as invokeArrayFns$1, hyphenate} from "@vue/shared"; import {injectHook, createVNode, inject, provide, reactive, computed, nextTick, getCurrentInstance, onBeforeMount, onMounted, onBeforeActivate, onBeforeDeactivate, openBlock, createBlock, mergeProps, toDisplayString, ref, defineComponent, resolveComponent, toHandlers, renderSlot, watch, onActivated, onBeforeUnmount, withModifiers, withDirectives, vShow, vModelDynamic, createTextVNode, createCommentVNode, Fragment, renderList, vModelText, onDeactivated, onUnmounted, watchEffect, withCtx, KeepAlive, resolveDynamicComponent} from "vue"; -import {once, passive, normalizeTarget, invokeArrayFns, NAVBAR_HEIGHT, parseQuery, removeLeadingSlash, getLen, ON_REACH_BOTTOM_DISTANCE, decodedQuery, plusReady, debounce, PRIMARY_COLOR as PRIMARY_COLOR$1, updateElementStyle, addFont, scrollTo} from "@dcloudio/uni-shared"; +import {once, passive, normalizeTarget, invokeArrayFns, NAVBAR_HEIGHT, parseQuery, PRIMARY_COLOR, removeLeadingSlash, getLen, ON_REACH_BOTTOM_DISTANCE, decodedQuery, plusReady, debounce, updateElementStyle, addFont, scrollTo} from "@dcloudio/uni-shared"; import {useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView} from "vue-router"; function applyOptions(options, instance2, publicThis) { Object.keys(options).forEach((name) => { @@ -2627,6 +2627,8 @@ function createNormalizeUrl(type) { } }; } +const API_HIDE_LOADING = "hideLoading"; +const API_HIDE_TOAST = "hideToast"; const API_LOAD_FONT_FACE = "loadFontFace"; const LoadFontFaceProtocol = { family: { @@ -2639,20 +2641,6 @@ const LoadFontFaceProtocol = { }, desc: Object }; -const API_PAGE_SCROLL_TO = "pageScrollTo"; -const PageScrollToProtocol = { - scrollTop: Number, - selector: String, - duration: Number -}; -const DEFAULT_DURATION = 300; -const PageScrollToOptions = { - formatArgs: { - duration(value, params) { - params.duration = Math.max(0, parseInt(value + "") || DEFAULT_DURATION); - } - } -}; const FRONT_COLORS = ["#ffffff", "#000000"]; const API_SET_NAVIGATION_BAR_COLOR = "setNavigationBarColor"; const SetNavigationBarColorOptions = { @@ -2693,7 +2681,44 @@ const SetNavigationBarTitleProtocol = { }; const API_SHOW_NAVIGATION_BAR_LOADING = "showNavigationBarLoading"; const API_HIDE_NAVIGATION_BAR_LOADING = "hideNavigationBarLoading"; -const PRIMARY_COLOR = "#007aff"; +const API_PAGE_SCROLL_TO = "pageScrollTo"; +const PageScrollToProtocol = { + scrollTop: Number, + selector: String, + duration: Number +}; +const DEFAULT_DURATION = 300; +const PageScrollToOptions = { + formatArgs: { + duration(value, params) { + params.duration = Math.max(0, parseInt(value + "") || DEFAULT_DURATION); + } + } +}; +const API_SHOW_ACTION_SHEET = "showActionSheet"; +const ShowActionSheetProtocol = { + itemList: { + type: Array, + required: true + }, + itemColor: String +}; +const ShowActionSheetOptions = { + formatArgs: { + itemColor: "#000" + } +}; +const API_SHOW_LOADING = "showLoading"; +const ShowLoadingProtocol = { + title: String, + mask: Boolean +}; +const ShowLoadingOptions = { + formatArgs: { + title: "", + mask: false + } +}; const API_SHOW_MODAL = "showModal"; const ShowModalProtocol = { title: String, @@ -2753,32 +2778,6 @@ const ShowToastOptions = { mask: false } }; -const API_SHOW_LOADING = "showLoading"; -const ShowLoadingProtocol = { - title: String, - mask: Boolean -}; -const ShowLoadingOptions = { - formatArgs: { - title: "", - mask: false - } -}; -const API_SHOW_ACTION_SHEET = "showActionSheet"; -const ShowActionSheetProtocol = { - itemList: { - type: Array, - required: true - }, - itemColor: String -}; -const ShowActionSheetOptions = { - formatArgs: { - itemColor: "#000" - } -}; -const API_HIDE_TOAST = "hideToast"; -const API_HIDE_LOADING = "hideLoading"; const API_START_PULL_DOWN_REFRESH = "startPullDownRefresh"; const API_STOP_PULL_DOWN_REFRESH = "stopPullDownRefresh"; const IndexProtocol = { @@ -5981,11 +5980,11 @@ const CANCEL_COLOR = "#f43530"; const ICONS = { success: { d: ICON_PATH_SUCCESS, - c: PRIMARY_COLOR$1 + c: PRIMARY_COLOR }, success_no_circle: { d: ICON_PATH_SUCCESS_NO_CIRCLE, - c: PRIMARY_COLOR$1 + c: PRIMARY_COLOR }, info: { d: ICON_PATH_INFO, @@ -6005,7 +6004,7 @@ const ICONS = { }, download: { d: ICON_PATH_DOWNLOAD, - c: PRIMARY_COLOR$1 + c: PRIMARY_COLOR }, search: { d: ICON_PATH_SEARCH, -- GitLab