diff --git a/packages/uni-api/src/index.ts b/packages/uni-api/src/index.ts index a564b5b68a7557cd7168bb8607f8115486cd2695..01a47e253986a5bc8c6d89c38421941fe6f945a8 100644 --- a/packages/uni-api/src/index.ts +++ b/packages/uni-api/src/index.ts @@ -98,6 +98,7 @@ export * from './protocols/plugin/getProvider' export * from './protocols/plugin/oauth' export * from './protocols/plugin/share' export * from './protocols/plugin/requestPayment' +export * from './protocols/plugin/push' // ad export * from './protocols/ad/rewardedVideoAd' diff --git a/packages/uni-api/src/protocols/plugin/push.ts b/packages/uni-api/src/protocols/plugin/push.ts new file mode 100644 index 0000000000000000000000000000000000000000..adbf7a05d372efd3f3aa087f398495fd8aaeb1ca --- /dev/null +++ b/packages/uni-api/src/protocols/plugin/push.ts @@ -0,0 +1,82 @@ +interface CreatePushMessageOptions { + /** + * 是否覆盖上一次提示的消息 + * 可取值true或false,true为覆盖,false不覆盖,默认为permission中设置的cover值 + * Android - ALL (支持) + * iOS - 5.0+ (不支持): 不支持覆盖消息,只能创建新的消息。 + */ + cover?: boolean + /** + * 提示消息延迟显示的时间 + * 当设备接收到推送消息后,可不立即显示,而是延迟一段时间显示,延迟时间单位为s,默认为0s,立即显示。 + */ + delay?: number + /** + * 推送消息的图标 + * 本地图片地址,相对路径 - 相对于当前页面的host位置,如"a.jpg",注意当前页面为网络地址则不支持; 绝对路径 - 系统绝对路径,如Android平台"/sdcard/logo.png",此类路径通常通过其它5+ API获取的; 扩展相对路径URL(RelativeURL) - 以"_"开头的相对路径,如"_www/a.jpg"; 本地路径URL - 以“file://”开头,后面跟随系统绝对路径。 + * Android - 2.3+ (支持) + * iOS - ALL (不支持): 不支持自定义图片,固定使用应用图标。 + */ + icon?: string + /** + * 推送消息的提示音 + * 显示消息时的播放的提示音,可取值: “system”-表示使用系统通知提示音; “none”-表示不使用提示音; 默认值为“system”。 + * Android - 2.3+ (支持) + * iOS - 5.1+ (支持): 当程序在前台运行时,提示音不生效。 注:通常应该设置延迟时间,当程序切换到后台才创建本地推送消息时生效。 + */ + sound?: 'system' | 'none' + /** + * 推送消息的标题 + * 在系统消息中心显示的通知消息标题,默认值为程序的名称。 + * Android - ALL (支持) + * iOS - 5.0+ (不支持): 不支持设置消息的标题,固定为程序的名称。 + */ + title?: string // 推送消息的标题 + /** + * 消息显示的内容,在系统通知中心中显示的文本内容。 + */ + content: string + /** + * 消息承载的数据,可根据业务逻辑自定义数据格式。 + */ + payload?: unknown + /** + * 直达的页面路径 + * 支持普通页面和tabBar页面,普通页面支持通过`?param1=value1`方式传参(tabBar页面不支持) + */ + path?: string + /** + * 消息上显示的提示时间 + * 默认为当前时间,如果延迟显示则使用延时后显示消息的时间。 + * Android - ALL (支持) + * iOS - 5.0+ (不支持): 不支持设定消息的显示时间,由系统自动管理消息的创建时间。 + */ + when?: Date + /** + * 接口调用成功的回调函数 + */ + success?: (result: unknown) => void + /** + * 接口调用失败的回调函数 + */ + fail?: (result: unknown) => void + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + */ + complete?: (result: unknown) => void +} +export const API_CREATE_PUSH_MESSAGE = 'createPushMessage' +export type API_TYPE_CREATE_PUSH_MESSAGE = ( + options: CreatePushMessageOptions +) => void + +export const CreatePushMessageOptions: ApiOptions = + { + formatArgs: { + content(value) { + if (!value) { + return `content is required` + } + }, + }, + } diff --git a/packages/uni-app-plus/dist/uni.runtime.esm.js b/packages/uni-app-plus/dist/uni.runtime.esm.js index 5e28f555ef2d6f811e80011baf6029d4456f9cff..683226b7859ed286c9c0c9ce7d682e938ab62595 100644 --- a/packages/uni-app-plus/dist/uni.runtime.esm.js +++ b/packages/uni-app-plus/dist/uni.runtime.esm.js @@ -11458,6 +11458,10 @@ const ScanCodeOptions = { }, }; +const API_GET_SYSTEM_SETTING = 'getSystemSetting'; + +const API_GET_APP_AUTHORIZE_SETTING = 'getAppAuthorizeSetting'; + const API_GET_STORAGE = 'getStorage'; const GetStorageProtocol = { key: { @@ -12628,6 +12632,17 @@ const RequestPaymentProtocol = { paySign: String, }; +const API_CREATE_PUSH_MESSAGE = 'createPushMessage'; +const CreatePushMessageOptions = { + formatArgs: { + content(value) { + if (!value) { + return `content is required`; + } + }, + }, +}; + const API_CREATE_REWARDED_VIDEO_AD = 'createRewardedVideoAd'; const CreateRewardedVideoAdOptions = { formatArgs: { @@ -14074,6 +14089,28 @@ const setKeepScreenOn = defineAsyncApi(API_SET_KEEP_SCREEN_ON, (options, { resol resolve(); }); +const getSystemSetting = defineSyncApi(API_GET_SYSTEM_SETTING, () => { + const { getSystemSetting } = weex.requireModule('plus'); + let systemSetting = getSystemSetting(); + try { + if (typeof systemSetting === 'string') + systemSetting = JSON.parse(systemSetting); + } + catch (error) { } + return systemSetting; +}); + +const getAppAuthorizeSetting = defineSyncApi(API_GET_APP_AUTHORIZE_SETTING, () => { + const { getAppAuthorizeSetting } = weex.requireModule('plus'); + let appAuthorizeSetting = getAppAuthorizeSetting(); + try { + if (typeof appAuthorizeSetting === 'string') + appAuthorizeSetting = JSON.parse(appAuthorizeSetting); + } + catch (error) { } + return appAuthorizeSetting; +}); + const getImageInfo = defineAsyncApi(API_GET_IMAGE_INFO, (options, { resolve, reject }) => { const path = TEMP_PATH + '/download/'; plus.io.getImageInfo(extend(options, { @@ -16736,6 +16773,21 @@ const getUniverifyManager = defineSyncApi(API_GET_UNIVERIFY_MANAGER, () => { return univerifyManager || (univerifyManager = new UniverifyManager()); }); +const createPushMessage = defineAsyncApi(API_CREATE_PUSH_MESSAGE, (opts, { resolve, reject }) => { + const setting = getAppAuthorizeSetting(); + if (!hasOwn$1(setting, 'notificationAuthorized')) { + return reject(`missing push module`); + } + if (setting.notificationAuthorized !== 'authorized') { + return reject(setting.notificationAuthorized); + } + const options = extend({}, opts); + delete options.content; + delete options.payload; + plus.push.createMessage(opts.content, opts.payload, options); + resolve(); +}, undefined, CreatePushMessageOptions); + const registerRuntime = defineSyncApi('registerRuntime', (runtime) => { // @ts-expect-error extend(jsRuntime, runtime); @@ -19162,6 +19214,8 @@ var uni$1 = { setScreenBrightness: setScreenBrightness, setKeepScreenOn: setKeepScreenOn, getWindowInfo: getWindowInfo, + getSystemSetting: getSystemSetting, + getAppAuthorizeSetting: getAppAuthorizeSetting, getImageInfo: getImageInfo, getVideoInfo: getVideoInfo, previewImage: previewImage, @@ -19227,6 +19281,7 @@ var uni$1 = { closeAuthView: closeAuthView, getCheckBoxState: getCheckBoxState, getUniverifyManager: getUniverifyManager, + createPushMessage: createPushMessage, registerRuntime: registerRuntime, share: share, shareWithSystem: shareWithSystem, diff --git a/packages/uni-app-plus/src/service/api/index.ts b/packages/uni-app-plus/src/service/api/index.ts index cba3af00dd790867f8aa7ceaca65cb5f20d01d2f..b2d4899e7a841421dbb4038a3be7635b9d419bb6 100644 --- a/packages/uni-app-plus/src/service/api/index.ts +++ b/packages/uni-app-plus/src/service/api/index.ts @@ -68,6 +68,7 @@ export * from './internal/global' export * from './plugin/getProvider' export * from './plugin/oauth' +export * from './plugin/push' export * from './plugin/registerRuntime' export * from './plugin/share' export * from './plugin/requestPayment' diff --git a/packages/uni-app-plus/src/service/api/plugin/push.ts b/packages/uni-app-plus/src/service/api/plugin/push.ts new file mode 100644 index 0000000000000000000000000000000000000000..7773bb2d89d61f1cd1d0d054182b3f4ad4ffd2c2 --- /dev/null +++ b/packages/uni-app-plus/src/service/api/plugin/push.ts @@ -0,0 +1,27 @@ +import { hasOwn, extend } from '@vue/shared' +import { + API_CREATE_PUSH_MESSAGE, + API_TYPE_CREATE_PUSH_MESSAGE, + CreatePushMessageOptions, + defineAsyncApi, +} from '@dcloudio/uni-api' +import { getAppAuthorizeSetting } from '../device/getAppAuthorizeSetting' +export const createPushMessage = defineAsyncApi( + API_CREATE_PUSH_MESSAGE, + (opts, { resolve, reject }) => { + const setting = getAppAuthorizeSetting() + if (!hasOwn(setting, 'notificationAuthorized')) { + return reject(`missing push module`) + } + if (setting.notificationAuthorized !== 'authorized') { + return reject(setting.notificationAuthorized) + } + const options = extend({}, opts) + delete (options as any).content + delete options.payload + plus.push.createMessage(opts.content, opts.payload as string, options) + resolve() + }, + undefined, + CreatePushMessageOptions +) diff --git a/packages/uni-cli-shared/src/json/manifest.ts b/packages/uni-cli-shared/src/json/manifest.ts index 53b81e28ee0a93179e8b1bf53ae29740d98601d5..893ddc9284cc090e07c1be084a90150e1f449b30 100644 --- a/packages/uni-cli-shared/src/json/manifest.ts +++ b/packages/uni-cli-shared/src/json/manifest.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import { extend } from '@vue/shared' +import { extend, hasOwn } from '@vue/shared' import { once, defaultRpx2Unit, @@ -66,6 +66,20 @@ export function getUniStatistics(inputDir: string, platform: UniApp.PLATFORM) { ) } +export function isEnableUniPushV1(inputDir: string, platform: UniApp.PLATFORM) { + if (isEnableUniPushV2(inputDir, platform)) { + return false + } + const manifest = parseManifestJsonOnce(inputDir) + if (platform === 'app') { + const push = manifest['app-plus']?.distribute?.sdkConfigs?.push + if (push && hasOwn(push, 'unipush')) { + return true + } + } + return false +} + export function isEnableUniPushV2(inputDir: string, platform: UniApp.PLATFORM) { const manifest = parseManifestJsonOnce(inputDir) if (platform === 'app') { diff --git a/packages/uni-components/dist/components.js b/packages/uni-components/dist/components.js index 2918ee2ee8686b7991fbff4fea9f51b7bd4d746f..be828f4c4dfbb71ef134550c9d5d8c2132b6d6fe 100644 --- a/packages/uni-components/dist/components.js +++ b/packages/uni-components/dist/components.js @@ -4400,7 +4400,7 @@ var RichText = defineComponent({ if (isString(nodes)) { nodes = parseHtml(nodes); } - return createVNode(resolveComponent("u-rich-text"), { + return createVNode("u-rich-text", { value: normalizeNodes(nodes || [], instance.root, { defaultFontSize }) diff --git a/packages/uni-push/lib/uni.plugin.js b/packages/uni-push/lib/uni.plugin.js index f1cc52bf79e4203cff6958ad719a5b7a69ac8626..a1737bea4c72e334cc7111f65357f0d4a9e3fe2e 100644 --- a/packages/uni-push/lib/uni.plugin.js +++ b/packages/uni-push/lib/uni.plugin.js @@ -9,7 +9,8 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path); var index = () => [ uniCliShared.defineUniMainJsPlugin((opts) => { - let isEnable = false; + let isEnableV1 = false; + let isEnableV2 = false; let isOffline = false; return { name: 'uni:push', @@ -20,10 +21,16 @@ var index = () => [ } const inputDir = process.env.UNI_INPUT_DIR; const platform = process.env.UNI_PLATFORM; - isEnable = uniCliShared.isEnableUniPushV2(inputDir, platform); - if (!isEnable) { + isEnableV1 = uniCliShared.isEnableUniPushV1(inputDir, platform); + isEnableV2 = uniCliShared.isEnableUniPushV2(inputDir, platform); + // v1 + if (isEnableV1) { return; } + if (!isEnableV2) { + return; + } + // v2 isOffline = platform === 'app' && uniCliShared.isUniPushOffline(inputDir); if (isOffline) { return; @@ -36,14 +43,16 @@ var index = () => [ }, resolveId(id) { if (id === '@dcloudio/uni-push') { - return uniCliShared.resolveBuiltIn(path__default["default"].join('@dcloudio/uni-push', isOffline ? 'dist/uni-push.plus.es.js' : 'dist/uni-push.es.js')); + return uniCliShared.resolveBuiltIn(path__default["default"].join('@dcloudio/uni-push', isOffline || isEnableV1 + ? 'dist/uni-push.plus.es.js' + : 'dist/uni-push.es.js')); } }, transform(code, id) { if (!opts.filter(id)) { return; } - if (isEnable) { + if (isEnableV1 || isEnableV2) { return { code: `import '@dcloudio/uni-push';` + code, map: null, diff --git a/packages/uni-push/src/plugin/index.ts b/packages/uni-push/src/plugin/index.ts index c4c73e310cea04a71cf05b707cb58b40546dcef7..38ab3b14bc6a894d631e678720dedbad82ce175b 100644 --- a/packages/uni-push/src/plugin/index.ts +++ b/packages/uni-push/src/plugin/index.ts @@ -2,6 +2,7 @@ import path from 'path' import { defineUniMainJsPlugin, isSsr, + isEnableUniPushV1, isEnableUniPushV2, isUniPushOffline, resolveBuiltIn, @@ -9,7 +10,8 @@ import { export default () => [ defineUniMainJsPlugin((opts) => { - let isEnable = false + let isEnableV1 = false + let isEnableV2 = false let isOffline = false return { name: 'uni:push', @@ -20,10 +22,16 @@ export default () => [ } const inputDir = process.env.UNI_INPUT_DIR! const platform = process.env.UNI_PLATFORM! - isEnable = isEnableUniPushV2(inputDir, platform) - if (!isEnable) { + isEnableV1 = isEnableUniPushV1(inputDir, platform) + isEnableV2 = isEnableUniPushV2(inputDir, platform) + // v1 + if (isEnableV1) { return } + if (!isEnableV2) { + return + } + // v2 isOffline = platform === 'app' && isUniPushOffline(inputDir) if (isOffline) { return @@ -39,7 +47,9 @@ export default () => [ return resolveBuiltIn( path.join( '@dcloudio/uni-push', - isOffline ? 'dist/uni-push.plus.es.js' : 'dist/uni-push.es.js' + isOffline || isEnableV1 + ? 'dist/uni-push.plus.es.js' + : 'dist/uni-push.es.js' ) ) } @@ -48,7 +58,7 @@ export default () => [ if (!opts.filter(id)) { return } - if (isEnable) { + if (isEnableV1 || isEnableV2) { return { code: `import '@dcloudio/uni-push';` + code, map: null, diff --git a/packages/uni-shared/dist/uni-shared.cjs.js b/packages/uni-shared/dist/uni-shared.cjs.js index db85b37ae724317b3c35597480605c7215006c03..770727a577202b2edbb2081b59861dfbfdca625a 100644 --- a/packages/uni-shared/dist/uni-shared.cjs.js +++ b/packages/uni-shared/dist/uni-shared.cjs.js @@ -122,6 +122,7 @@ const NVUE_U_BUILT_IN_TAGS = [ 'u-slider', 'u-ad', 'u-ad-draw', + 'u-rich-text', ]; function isBuiltInComponent(tag) { // h5 平台会被转换为 v-uni- diff --git a/packages/uni-shared/dist/uni-shared.es.js b/packages/uni-shared/dist/uni-shared.es.js index 962d602febde5173c05d19fee282a1ed3a589cab..a55764f1773546274b4fcc71d50c7b8239dd0678 100644 --- a/packages/uni-shared/dist/uni-shared.es.js +++ b/packages/uni-shared/dist/uni-shared.es.js @@ -118,6 +118,7 @@ const NVUE_U_BUILT_IN_TAGS = [ 'u-slider', 'u-ad', 'u-ad-draw', + 'u-rich-text', ]; function isBuiltInComponent(tag) { // h5 平台会被转换为 v-uni-