提交 0d56f757 编写于 作者: fxy060608's avatar fxy060608

feat(app): createPushMessage

上级 37e44116
......@@ -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'
......
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<API_TYPE_CREATE_PUSH_MESSAGE> =
{
formatArgs: {
content(value) {
if (!value) {
return `content is required`
}
},
},
}
......@@ -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,
......
......@@ -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'
......
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_TYPE_CREATE_PUSH_MESSAGE>(
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
)
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') {
......
......@@ -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
})
......
......@@ -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,
......
......@@ -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,
......
......@@ -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-
......
......@@ -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-
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册