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

wip(app): uni-app-plus

上级 1aaf8d7e
dist dist
\ No newline at end of file lib
\ No newline at end of file
...@@ -23,6 +23,9 @@ describe('dom', () => { ...@@ -23,6 +23,9 @@ describe('dom', () => {
route: 'pages/index/index', route: 'pages/index/index',
version: 1, version: 1,
locale: 'zh_CN', locale: 'zh_CN',
platform: 'ios',
pixelRatio: 1,
windowWidth: 375,
disableScroll: false, disableScroll: false,
onPageScroll: false, onPageScroll: false,
onPageReachBottom: false, onPageReachBottom: false,
......
...@@ -19,6 +19,9 @@ const defaultPageNodeOptions = { ...@@ -19,6 +19,9 @@ const defaultPageNodeOptions = {
route: 'pages/index/index', route: 'pages/index/index',
version: 1, version: 1,
locale: 'zh_CN', locale: 'zh_CN',
platform: 'ios',
pixelRatio: 1,
windowWidth: 375,
disableScroll: false, disableScroll: false,
onPageScroll: false, onPageScroll: false,
onPageReachBottom: false, onPageReachBottom: false,
......
...@@ -594,6 +594,23 @@ var serviceContext = (function (vue) { ...@@ -594,6 +594,23 @@ var serviceContext = (function (vue) {
return encode$3(arrayBuffer); return encode$3(arrayBuffer);
}, ArrayBufferToBase64Protocol); }, ArrayBufferToBase64Protocol);
/**
* 简易版systemInfo,主要为upx2px,i18n服务
* @returns
*/
function getBaseSystemInfo() {
// @ts-expect-error view 层
if (typeof __SYSTEM_INFO__ !== 'undefined') {
return window.__SYSTEM_INFO__;
}
const { resolutionWidth } = plus.screen.getCurrentSize();
return {
platform: (plus.os.name || '').toLowerCase(),
pixelRatio: plus.screen.scale,
windowWidth: Math.round(resolutionWidth),
};
}
function formatLog(module, ...args) { function formatLog(module, ...args) {
return `[${Date.now()}][${module}]:${args return `[${Date.now()}][${module}]:${args
.map((arg) => JSON.stringify(arg)) .map((arg) => JSON.stringify(arg))
...@@ -1556,6 +1573,7 @@ var serviceContext = (function (vue) { ...@@ -1556,6 +1573,7 @@ var serviceContext = (function (vue) {
} }
function hasRpx(str) { function hasRpx(str) {
str = str + '';
return str.indexOf('rpx') !== -1 || str.indexOf('upx') !== -1; return str.indexOf('rpx') !== -1 || str.indexOf('upx') !== -1;
} }
function rpx2px(str, replace = false) { function rpx2px(str, replace = false) {
...@@ -2454,6 +2472,35 @@ var serviceContext = (function (vue) { ...@@ -2454,6 +2472,35 @@ var serviceContext = (function (vue) {
timeout: Number, timeout: Number,
}; };
const API_UPLOAD_FILE = 'uploadFile';
const UploadFileOptions = {
formatArgs: {
filePath(filePath, params) {
if (filePath) {
params.filePath = getRealPath(filePath);
}
},
header(value, params) {
params.header = value || {};
},
formData(value, params) {
params.formData = value || {};
},
},
};
const UploadFileProtocol = {
url: {
type: String,
required: true,
},
files: Array,
filePath: String,
name: String,
header: Object,
formData: Object,
timeout: Number,
};
const API_CONNECT_SOCKET = 'connectSocket'; const API_CONNECT_SOCKET = 'connectSocket';
const ConnectSocketOptions = { const ConnectSocketOptions = {
formatArgs: { formatArgs: {
...@@ -4517,32 +4564,13 @@ var serviceContext = (function (vue) { ...@@ -4517,32 +4564,13 @@ var serviceContext = (function (vue) {
}); });
}); });
this._socket.onerror(() => { this._socket.onerror(() => {
this.onErrorOrClose();
this.socketStateChange('error'); this.socketStateChange('error');
this.onErrorOrClose();
}); });
this._socket.onclose(() => { this._socket.onclose(() => {
this.onErrorOrClose();
this.socketStateChange('close'); this.socketStateChange('close');
this.onErrorOrClose();
}); });
const oldSocketSend = this._socket.send;
const oldSocketClose = this._socket.close;
this._socket.send = (res) => {
oldSocketSend(extend({
id: this.id,
data: typeof res.data === 'object'
? {
'@type': 'binary',
base64: arrayBufferToBase64(res.data),
}
: res.data,
}));
};
this._socket.close = (res) => {
oldSocketClose(extend({
id: this.id,
res,
}));
};
} }
onErrorOrClose() { onErrorOrClose() {
this.readyState = this.CLOSED; this.readyState = this.CLOSED;
...@@ -4568,7 +4596,13 @@ var serviceContext = (function (vue) { ...@@ -4568,7 +4596,13 @@ var serviceContext = (function (vue) {
} }
try { try {
this._socket.send({ this._socket.send({
data: args.data, id: this.id,
data: typeof args.data === 'object'
? {
'@type': 'binary',
base64: arrayBufferToBase64(args.data),
}
: args.data,
}); });
callOptions(args, 'sendSocketMessage:ok'); callOptions(args, 'sendSocketMessage:ok');
} }
...@@ -4579,7 +4613,10 @@ var serviceContext = (function (vue) { ...@@ -4579,7 +4613,10 @@ var serviceContext = (function (vue) {
close(args) { close(args) {
this.readyState = this.CLOSING; this.readyState = this.CLOSING;
try { try {
this._socket.close(args); this._socket.close(extend({
id: this.id,
args,
}));
callOptions(args, 'closeSocket:ok'); callOptions(args, 'closeSocket:ok');
} }
catch (error) { catch (error) {
...@@ -4626,9 +4663,7 @@ var serviceContext = (function (vue) { ...@@ -4626,9 +4663,7 @@ var serviceContext = (function (vue) {
reject('sendSocketMessage:fail WebSocket is not connected'); reject('sendSocketMessage:fail WebSocket is not connected');
return; return;
} }
socketTask._socket.send({ socketTask.send({ data: args.data });
data: args.data,
});
resolve(); resolve();
}, SendSocketMessageProtocol); }, SendSocketMessageProtocol);
const closeSocket = defineAsyncApi(API_CLOSE_SOCKET, (args, { resolve, reject }) => { const closeSocket = defineAsyncApi(API_CLOSE_SOCKET, (args, { resolve, reject }) => {
...@@ -4639,7 +4674,7 @@ var serviceContext = (function (vue) { ...@@ -4639,7 +4674,7 @@ var serviceContext = (function (vue) {
} }
socketTask.readyState = socketTask.CLOSING; socketTask.readyState = socketTask.CLOSING;
const { code, reason } = args; const { code, reason } = args;
socketTask._socket.close({ code, reason }); socketTask.close({ code, reason });
resolve(); resolve();
}, CloseSocketProtocol); }, CloseSocketProtocol);
function on(event) { function on(event) {
...@@ -4653,6 +4688,84 @@ var serviceContext = (function (vue) { ...@@ -4653,6 +4688,84 @@ var serviceContext = (function (vue) {
const onSocketMessage = /*#__PURE__*/ on('message'); const onSocketMessage = /*#__PURE__*/ on('message');
const onSocketClose = /*#__PURE__*/ on('close'); const onSocketClose = /*#__PURE__*/ on('close');
class UploadTask {
constructor(uploader) {
this._callbacks = [];
this._uploader = uploader;
uploader.addEventListener('statechanged', (upload, status) => {
if (upload.uploadedSize && upload.totalSize) {
this._callbacks.forEach((callback) => {
callback({
progress: parseInt(String((upload.uploadedSize / upload.totalSize) * 100)),
totalBytesSent: upload.uploadedSize,
totalBytesExpectedToSend: upload.totalSize,
});
});
}
});
}
abort() {
this._uploader.abort();
}
onProgressUpdate(callback) {
if (typeof callback !== 'function') {
return;
}
this._callbacks.push(callback);
}
onHeadersReceived() { }
offProgressUpdate(callback) {
const index = this._callbacks.indexOf(callback);
if (index >= 0) {
this._callbacks.splice(index, 1);
}
}
offHeadersReceived() { }
}
const uploadFile = defineTaskApi(API_UPLOAD_FILE, ({ url, timeout, header, formData, files, filePath, name }, { resolve, reject }) => {
const uploader = plus.uploader.createUpload(url, {
timeout,
// 需要与其它平台上的表现保持一致,不走重试的逻辑。
retry: 0,
retryInterval: 0,
}, (upload, statusCode) => {
if (statusCode) {
resolve({
data: upload.responseText,
statusCode,
});
}
else {
reject(`statusCode: ${statusCode}`);
}
});
for (const name in header) {
if (hasOwn$1(header, name)) {
uploader.setRequestHeader(name, String(header[name]));
}
}
for (const name in formData) {
if (hasOwn$1(formData, name)) {
uploader.addData(name, String(formData[name]));
}
}
if (files && files.length) {
files.forEach((file) => {
uploader.addFile(getRealPath(file.uri), {
key: file.name || 'file',
});
});
}
else {
uploader.addFile(getRealPath(filePath), {
key: name,
});
}
const uploadFileTask = new UploadTask(uploader);
uploader.start();
return uploadFileTask;
}, UploadFileProtocol, UploadFileOptions);
const audios = {}; const audios = {};
const evts = [ const evts = [
'play', 'play',
...@@ -4698,7 +4811,7 @@ var serviceContext = (function (vue) { ...@@ -4698,7 +4811,7 @@ var serviceContext = (function (vue) {
}; };
function createAudioInstance() { function createAudioInstance() {
const audioId = `${Date.now()}${Math.random()}`; const audioId = `${Date.now()}${Math.random()}`;
const audio = (audios[audioId] = plus.audio.createPlayer()); const audio = (audios[audioId] = plus.audio.createPlayer('')); // 此处空字符串必填
audio.src = ''; audio.src = '';
audio.volume = 1; audio.volume = 1;
audio.startTime = 0; audio.startTime = 0;
...@@ -6224,7 +6337,8 @@ var serviceContext = (function (vue) { ...@@ -6224,7 +6337,8 @@ var serviceContext = (function (vue) {
} }
const VD_SYNC = 'vdSync'; const VD_SYNC = 'vdSync';
const ON_WEBVIEW_READY = 'onWebviewReady'; const ON_WEBVIEW_READY = 'onWebviewReady';
const INVOKE_API = 'invokeApi';
const ACTION_TYPE_PAGE_CREATE = 1; const ACTION_TYPE_PAGE_CREATE = 1;
const ACTION_TYPE_PAGE_CREATED = 2; const ACTION_TYPE_PAGE_CREATED = 2;
...@@ -6580,7 +6694,11 @@ var serviceContext = (function (vue) { ...@@ -6580,7 +6694,11 @@ var serviceContext = (function (vue) {
// 非纯原生 // 非纯原生
subscribe(ON_WEBVIEW_READY, subscribeWebviewReady); subscribe(ON_WEBVIEW_READY, subscribeWebviewReady);
subscribe(VD_SYNC, onVdSync); subscribe(VD_SYNC, onVdSync);
subscribe(INVOKE_API, onInvokeApi);
} }
}
function onInvokeApi({ data: { method, args }, }) {
uni[method] && uni[method](args);
} }
let appCtx; let appCtx;
...@@ -7450,11 +7568,15 @@ var serviceContext = (function (vue) { ...@@ -7450,11 +7568,15 @@ var serviceContext = (function (vue) {
} }
function initPageOptions({ meta }) { function initPageOptions({ meta }) {
const statusbarHeight = getStatusbarHeight(); const statusbarHeight = getStatusbarHeight();
const { platform, pixelRatio, windowWidth } = getBaseSystemInfo();
return { return {
css: true, css: true,
route: meta.route, route: meta.route,
version: 1, version: 1,
locale: '', locale: '',
platform,
pixelRatio,
windowWidth,
disableScroll: meta.disableScroll === true, disableScroll: meta.disableScroll === true,
onPageScroll: false, onPageScroll: false,
onPageReachBottom: false, onPageReachBottom: false,
...@@ -7699,6 +7821,7 @@ var serviceContext = (function (vue) { ...@@ -7699,6 +7821,7 @@ var serviceContext = (function (vue) {
onSocketError: onSocketError, onSocketError: onSocketError,
onSocketMessage: onSocketMessage, onSocketMessage: onSocketMessage,
onSocketClose: onSocketClose, onSocketClose: onSocketClose,
uploadFile: uploadFile,
createInnerAudioContext: createInnerAudioContext, createInnerAudioContext: createInnerAudioContext,
getBackgroundAudioManager: getBackgroundAudioManager, getBackgroundAudioManager: getBackgroundAudioManager,
getLocation: getLocation, getLocation: getLocation,
......
...@@ -18,6 +18,9 @@ export interface PageNodeOptions { ...@@ -18,6 +18,9 @@ export interface PageNodeOptions {
route: string route: string
version: number version: number
locale: string locale: string
platform: string
pixelRatio: number
windowWidth: number
disableScroll: boolean disableScroll: boolean
onPageScroll: boolean onPageScroll: boolean
onPageReachBottom: boolean onPageReachBottom: boolean
......
export const VD_SYNC = 'vdSync' export const VD_SYNC = 'vdSync'
export const ON_WEBVIEW_READY = 'onWebviewReady' export const ON_WEBVIEW_READY = 'onWebviewReady'
export const INVOKE_API = 'invokeApi'
...@@ -8,14 +8,7 @@ import { ...@@ -8,14 +8,7 @@ import {
SelectorQueryRequest, SelectorQueryRequest,
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
export function getBaseSystemInfo() { export { getBaseSystemInfo } from '../service/api/base/getBaseSystemInfo'
// TODO
return {
platform: '',
pixelRatio: 1,
windowWidth: 750,
}
}
export { getRealPath } from './getRealPath' export { getRealPath } from './getRealPath'
export function operateVideoPlayer( export function operateVideoPlayer(
videoId: string, videoId: string,
......
/**
* 简易版systemInfo,主要为upx2px,i18n服务
* @returns
*/
export function getBaseSystemInfo() {
// @ts-expect-error view 层
if (typeof __SYSTEM_INFO__ !== 'undefined') {
return (window as any).__SYSTEM_INFO__
}
const { resolutionWidth } = plus.screen.getCurrentSize()
return {
platform: (plus.os.name || '').toLowerCase(),
pixelRatio: plus.screen.scale!,
windowWidth: Math.round(resolutionWidth),
}
}
import { ON_WEBVIEW_READY, VD_SYNC } from '../../../../constants' import { INVOKE_API, ON_WEBVIEW_READY, VD_SYNC } from '../../../../constants'
import { onVdSync } from '../../dom' import { onVdSync } from '../../dom'
import { onPlusMessage } from '../initGlobalEvent' import { onPlusMessage } from '../initGlobalEvent'
import { subscribeWebviewReady } from './webviewReady' import { subscribeWebviewReady } from './webviewReady'
...@@ -17,5 +17,14 @@ export function initSubscribeHandlers() { ...@@ -17,5 +17,14 @@ export function initSubscribeHandlers() {
// 非纯原生 // 非纯原生
subscribe(ON_WEBVIEW_READY, subscribeWebviewReady) subscribe(ON_WEBVIEW_READY, subscribeWebviewReady)
subscribe(VD_SYNC, onVdSync) subscribe(VD_SYNC, onVdSync)
subscribe(INVOKE_API, onInvokeApi)
} }
} }
function onInvokeApi({
data: { method, args },
}: {
data: { method: UniApp.OpenType; args: any }
}) {
uni[method] && uni[method](args)
}
...@@ -15,6 +15,7 @@ import { PageNodeOptions } from '../../../PageAction' ...@@ -15,6 +15,7 @@ import { PageNodeOptions } from '../../../PageAction'
import { getStatusbarHeight } from '../../../helpers/statusBar' import { getStatusbarHeight } from '../../../helpers/statusBar'
import tabBar from '../app/tabBar' import tabBar from '../app/tabBar'
import { addCurrentPage } from './getCurrentPages' import { addCurrentPage } from './getCurrentPages'
import { getBaseSystemInfo } from '../../api/base/getBaseSystemInfo'
interface RegisterPageOptions { interface RegisterPageOptions {
url: string url: string
...@@ -89,11 +90,15 @@ export function registerPage({ ...@@ -89,11 +90,15 @@ export function registerPage({
function initPageOptions({ meta }: UniApp.UniRoute): PageNodeOptions { function initPageOptions({ meta }: UniApp.UniRoute): PageNodeOptions {
const statusbarHeight = getStatusbarHeight() const statusbarHeight = getStatusbarHeight()
const { platform, pixelRatio, windowWidth } = getBaseSystemInfo()
return { return {
css: true, css: true,
route: meta.route, route: meta.route,
version: 1, version: 1,
locale: '', locale: '',
platform,
pixelRatio,
windowWidth,
disableScroll: meta.disableScroll === true, disableScroll: meta.disableScroll === true,
onPageScroll: false, onPageScroll: false,
onPageReachBottom: false, onPageReachBottom: false,
......
export { upx2px } from '@dcloudio/uni-api'
export * from './route'
import { INVOKE_API } from '../../constants'
function invokeApi(method: string, args: Record<string, any> = {}) {
UniViewJSBridge.publishHandler(INVOKE_API, {
data: {
method,
args,
},
options: {
timestamp: Date.now(),
},
})
}
export function navigateTo(args: Record<string, any>) {
invokeApi('navigateTo', args)
}
export function navigateBack(args: Record<string, any>) {
invokeApi('navigateBack', args)
}
export function reLaunch(args: Record<string, any>) {
invokeApi('reLaunch', args)
}
export function redirectTo(args: Record<string, any>) {
invokeApi('redirectTo', args)
}
export function switchTab(args: Record<string, any>) {
invokeApi('switchTab', args)
}
import { defineBuiltInComponent } from '@dcloudio/uni-components'
export default /*#__PURE__*/ defineBuiltInComponent({
name: 'Ad',
})
import { defineBuiltInComponent } from '@dcloudio/uni-components'
export default /*#__PURE__*/ defineBuiltInComponent({
name: 'Map',
})
import { defineBuiltInComponent } from '@dcloudio/uni-components'
export default /*#__PURE__*/ defineBuiltInComponent({
name: 'Picker',
})
import { defineBuiltInComponent } from '@dcloudio/uni-components'
export default /*#__PURE__*/ defineBuiltInComponent({
name: 'WebView',
})
import Ad from '../../../components/ad'
import { UniComponent } from './UniComponent'
export class UniAd extends UniComponent {
constructor(id: number) {
super(id, 'uni-ad', Ad)
}
}
import '@dcloudio/uni-components/style/audio.css'
import { Audio } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniAudio extends UniComponent {
constructor(id: number) {
super(id, 'uni-audio', Audio)
}
}
import { UniNode } from '../elements/UniNode'
export class UniCamera extends UniNode {
constructor(id: number) {
super(id, 'uni-camera')
}
}
import '@dcloudio/uni-components/style/canvas.css'
import { Canvas } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniCanvas extends UniComponent {
constructor(id: number) {
super(id, 'uni-canvas', Canvas)
}
}
import '@dcloudio/uni-components/style/checkbox.css'
import { Checkbox } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniCheckbox extends UniComponent {
constructor(id: number) {
super(id, 'uni-checkbox', Checkbox)
}
}
import '@dcloudio/uni-components/style/checkbox-group.css'
import { CheckboxGroup } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniCheckboxGroup extends UniComponent {
constructor(id: number) {
super(id, 'uni-checkbox-group', CheckboxGroup)
}
}
import CoverImage from '../../../components/cover-image'
import { UniComponent } from './UniComponent'
export class UniCoverImage extends UniComponent {
constructor(id: number) {
super(id, 'uni-cover-image', CoverImage)
}
}
import CoverView from '../../../components/cover-view'
import { UniComponent } from './UniComponent'
export class UniCoverView extends UniComponent {
constructor(id: number) {
super(id, 'uni-cover-view', CoverView)
}
}
import '@dcloudio/uni-components/style/editor.css'
import { Editor } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniEditor extends UniComponent {
constructor(id: number) {
super(id, 'uni-editor', Editor)
}
}
import '@dcloudio/uni-components/style/form.css'
import { Form } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniForm extends UniComponent {
constructor(id: number) {
super(id, 'uni-form', Form)
}
}
import { UniNode } from '../elements/UniNode'
export class UniFunctionalPageNavigator extends UniNode {
constructor(id: number) {
super(id, 'uni-functional-page-navigator')
}
}
import '@dcloudio/uni-components/style/icon.css'
import { Icon } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniIcon extends UniComponent {
constructor(id: number) {
super(id, 'uni-icon', Icon)
}
}
import '@dcloudio/uni-components/style/image.css'
import { Image } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniImage extends UniComponent {
constructor(id: number) {
super(id, 'uni-image', Image)
}
}
import '@dcloudio/uni-components/style/input.css'
import { Input } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniInput extends UniComponent {
constructor(id: number) {
super(id, 'uni-input', Input)
}
}
import '@dcloudio/uni-components/style/label.css'
import { Label } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniLabel extends UniComponent {
constructor(id: number) {
super(id, 'uni-label', Label)
}
}
import { UniNode } from '../elements/UniNode'
export class UniLivePlayer extends UniNode {
constructor(id: number) {
super(id, 'uni-live-player')
}
}
import { UniNode } from '../elements/UniNode'
export class UniLivePusher extends UniNode {
constructor(id: number) {
super(id, 'uni-live-pusher')
}
}
import Map from '../../../components/map'
import { UniComponent } from './UniComponent'
export class UniMap extends UniComponent {
constructor(id: number) {
super(id, 'uni-map', Map)
}
}
import '@dcloudio/uni-components/style/movable-area.css'
import { MovableArea } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniMovableArea extends UniComponent {
constructor(id: number) {
super(id, 'uni-movable-area', MovableArea)
}
}
import '@dcloudio/uni-components/style/movable-view.css'
import { MovableView } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniMovableView extends UniComponent {
constructor(id: number) {
super(id, 'uni-movable-view', MovableView)
}
}
import '@dcloudio/uni-components/style/navigator.css'
import { Navigator } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniNavigator extends UniComponent {
constructor(id: number) {
super(id, 'uni-navigator', Navigator)
}
}
import { UniNode } from '../elements/UniNode'
export class UniOfficialAccount extends UniNode {
constructor(id: number) {
super(id, 'uni-official-account')
}
}
import { UniNode } from '../elements/UniNode'
export class UniOpenData extends UniNode {
constructor(id: number) {
super(id, 'uni-open-data')
}
}
import Picker from '../../../components/picker'
import { UniComponent } from './UniComponent'
export class UniPicker extends UniComponent {
constructor(id: number) {
super(id, 'uni-picker', Picker)
}
}
import '@dcloudio/uni-components/style/picker-view.css'
import { PickerView } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniPickerView extends UniComponent {
constructor(id: number) {
super(id, 'uni-picker-view', PickerView)
}
}
import '@dcloudio/uni-components/style/picker-view-column.css'
import { PickerViewColumn } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniPickerViewColumn extends UniComponent {
constructor(id: number) {
super(id, 'uni-picker-view-column', PickerViewColumn)
}
}
import '@dcloudio/uni-components/style/progress.css'
import { Progress } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniProgress extends UniComponent {
constructor(id: number) {
super(id, 'uni-progress', Progress)
}
}
import '@dcloudio/uni-components/style/radio.css'
import { Radio } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniRadio extends UniComponent {
constructor(id: number) {
super(id, 'uni-radio', Radio)
}
}
import '@dcloudio/uni-components/style/radio-group.css'
import { RadioGroup } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniRadioGroup extends UniComponent {
constructor(id: number) {
super(id, 'uni-radio-group', RadioGroup)
}
}
import '@dcloudio/uni-components/style/rich-text.css'
import { RichText } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniRichText extends UniComponent {
constructor(id: number) {
super(id, 'uni-rich-text', RichText)
}
}
import '@dcloudio/uni-components/style/scroll-view.css'
import { ScrollView } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniScrollView extends UniComponent {
constructor(id: number) {
super(id, 'uni-scroll-view', ScrollView)
}
}
import '@dcloudio/uni-components/style/slider.css'
import { Slider } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniSlider extends UniComponent {
constructor(id: number) {
super(id, 'uni-slider', Slider)
}
}
import '@dcloudio/uni-components/style/swiper.css'
import { Swiper } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniSwiper extends UniComponent {
constructor(id: number) {
super(id, 'uni-swiper', Swiper)
}
}
import '@dcloudio/uni-components/style/swiper-item.css'
import { SwiperItem } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniSwiperItem extends UniComponent {
constructor(id: number) {
super(id, 'uni-swiper-item', SwiperItem)
}
}
import '@dcloudio/uni-components/style/switch.css'
import { Switch } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniSwitch extends UniComponent {
constructor(id: number) {
super(id, 'uni-switch', Switch)
}
}
import '@dcloudio/uni-components/style/text.css'
import { Text } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniText extends UniComponent {
constructor(id: number) {
super(id, 'uni-text', Text)
}
}
import '@dcloudio/uni-components/style/textarea.css'
import { Textarea } from '@dcloudio/uni-components'
import { UniComponent } from './UniComponent'
export class UniTextarea extends UniComponent {
constructor(id: number) {
super(id, 'uni-textarea', Textarea)
}
}
import '../../../../../style/video.css'
import Video from '../../../components/video'
import { UniComponent } from './UniComponent'
export class UniVideo extends UniComponent {
constructor(id: number) {
super(id, 'uni-video', Video)
}
}
import WebView from '../../../components/web-view'
import { UniComponent } from './UniComponent'
export class UniWebView extends UniComponent {
constructor(id: number) {
super(id, 'uni-web-view', WebView)
}
}
import { defineComponent, h } from 'vue' import { defineComponent, h } from 'vue'
import { UniComment } from '../elements/UniComment' import { UniComment } from '../elements/UniComment'
import { UniText } from '../elements/UniText' import { UniTextNode } from '../elements/UniTextNode'
import { UniViewElement } from '../elements/UniViewElement' import { UniViewElement } from '../elements/UniViewElement'
import { UniAd } from './UniAd'
import { UniAudio } from './UniAudio'
import { UniButton } from './UniButton' import { UniButton } from './UniButton'
import { UniCamera } from './UniCamera'
import { UniCanvas } from './UniCanvas'
import { UniCheckbox } from './UniCheckbox'
import { UniCheckboxGroup } from './UniCheckboxGroup'
import { UniCoverImage } from './UniCoverImage'
import { UniCoverView } from './UniCoverView'
import { UniEditor } from './UniEditor'
import { UniForm } from './UniForm'
import { UniFunctionalPageNavigator } from './UniFunctionalPageNavigator'
import { UniIcon } from './UniIcon'
import { UniImage } from './UniImage'
import { UniInput } from './UniInput'
import { UniLabel } from './UniLabel'
import { UniLivePlayer } from './UniLivePlayer'
import { UniLivePusher } from './UniLivePusher'
import { UniMap } from './UniMap'
import { UniMovableArea } from './UniMovableArea'
import { UniMovableView } from './UniMovableView'
import { UniNavigator } from './UniNavigator'
import { UniOfficialAccount } from './UniOfficialAccount'
import { UniOpenData } from './UniOpenData'
import { UniPicker } from './UniPicker'
import { UniPickerView } from './UniPickerView'
import { UniPickerViewColumn } from './UniPickerViewColumn'
import { UniProgress } from './UniProgress'
import { UniRadio } from './UniRadio'
import { UniRadioGroup } from './UniRadioGroup'
import { UniRichText } from './UniRichText'
import { UniScrollView } from './UniScrollView'
import { UniSlider } from './UniSlider'
import { UniSwiper } from './UniSwiper'
import { UniSwiperItem } from './UniSwiperItem'
import { UniSwitch } from './UniSwitch'
import { UniText } from './UniText'
import { UniTextarea } from './UniTextarea'
import { UniVideo } from './UniVideo'
import { UniWebView } from './UniWebView'
export interface UniCustomElement extends Element { export interface UniCustomElement extends Element {
__id: number __id: number
...@@ -12,13 +51,48 @@ export interface UniCustomElement extends Element { ...@@ -12,13 +51,48 @@ export interface UniCustomElement extends Element {
const BuiltInComponents = [ const BuiltInComponents = [
, ,
UniViewElement, UniViewElement,
, UniImage,
,
UniText, UniText,
UniTextNode,
UniComment, UniComment,
, UniNavigator,
, UniForm,
UniButton, UniButton,
UniInput,
UniLabel,
UniRadio,
UniCheckbox,
UniCheckboxGroup,
UniAd,
UniAudio,
UniCamera,
UniCanvas,
UniCoverImage,
UniCoverView,
UniEditor,
UniFunctionalPageNavigator,
UniIcon,
UniRadioGroup,
UniLivePlayer,
UniLivePusher,
UniMap,
UniMovableArea,
UniMovableView,
UniOfficialAccount,
UniOpenData,
UniPicker,
UniPickerView,
UniPickerViewColumn,
UniProgress,
UniRichText,
UniScrollView,
UniSlider,
UniSwiper,
UniSwiperItem,
UniSwitch,
UniTextarea,
UniVideo,
UniWebView,
] ]
export type WrapperComponent = ReturnType<typeof createWrapper> export type WrapperComponent = ReturnType<typeof createWrapper>
......
import { UniNode } from './UniNode' import { UniNode } from './UniNode'
export class UniText extends UniNode { export class UniTextNode extends UniNode {
constructor(id: number) { constructor(id: number) {
super(id, '#text') super(id, '#text')
this.$ = document.createTextNode('') this.$ = document.createTextNode('')
......
import { rpx2px } from '@dcloudio/uni-core'
import { camelize, capitalize, hyphenate, isArray, isString } from '@vue/shared' import { camelize, capitalize, hyphenate, isArray, isString } from '@vue/shared'
export function patchStyle(el: Element, value: string | Record<string, any>) { export function patchStyle(el: Element, value: string | Record<string, any>) {
...@@ -7,7 +8,7 @@ export function patchStyle(el: Element, value: string | Record<string, any>) { ...@@ -7,7 +8,7 @@ export function patchStyle(el: Element, value: string | Record<string, any>) {
el.removeAttribute('style') el.removeAttribute('style')
} else { } else {
// TODO display // TODO display
style.cssText = value style.cssText = rpx2px(value, true)
} }
} else { } else {
for (const key in value) { for (const key in value) {
...@@ -26,6 +27,7 @@ function setStyle( ...@@ -26,6 +27,7 @@ function setStyle(
if (isArray(val)) { if (isArray(val)) {
val.forEach((v) => setStyle(style, name, v)) val.forEach((v) => setStyle(style, name, v))
} else { } else {
val = rpx2px(val, true)
if (name.startsWith('--')) { if (name.startsWith('--')) {
// custom property definition // custom property definition
style.setProperty(name, val) style.setProperty(name, val)
......
...@@ -35,6 +35,9 @@ export function onPageCreated() {} ...@@ -35,6 +35,9 @@ export function onPageCreated() {}
export function onPageCreate({ export function onPageCreate({
css, css,
route, route,
platform,
pixelRatio,
windowWidth,
disableScroll, disableScroll,
onPageScroll, onPageScroll,
onPageReachBottom, onPageReachBottom,
...@@ -43,6 +46,7 @@ export function onPageCreate({ ...@@ -43,6 +46,7 @@ export function onPageCreate({
windowTop, windowTop,
windowBottom, windowBottom,
}: PageCreateData) { }: PageCreateData) {
initSystemInfo(platform, pixelRatio, windowWidth)
// 初始化页面容器元素 // 初始化页面容器元素
initPageElement() initPageElement()
...@@ -63,6 +67,18 @@ export function onPageCreate({ ...@@ -63,6 +67,18 @@ export function onPageCreate({
} }
} }
function initSystemInfo(
platform: string,
pixelRatio: number,
windowWidth: number
) {
;(window as any).__SYSTEM_INFO__ = {
platform,
pixelRatio,
windowWidth,
}
}
function initPageElement() { function initPageElement() {
createElement(0, 'div').$ = document.getElementById('app')! createElement(0, 'div').$ = document.getElementById('app')!
} }
......
...@@ -4,7 +4,10 @@ import '@dcloudio/uni-h5/style/framework/nvue.css' ...@@ -4,7 +4,10 @@ import '@dcloudio/uni-h5/style/framework/nvue.css'
import { ON_WEBVIEW_READY } from '../constants' import { ON_WEBVIEW_READY } from '../constants'
import { UniViewJSBridge } from './bridge' import { UniViewJSBridge } from './bridge'
import { initView } from './framework' import { initView } from './framework'
import * as uni from './api'
;(window as any).uni = uni
;(window as any).UniViewJSBridge = UniViewJSBridge ;(window as any).UniViewJSBridge = UniViewJSBridge
;(window as any).rpx2px = uni.upx2px
function onWebviewReady() { function onWebviewReady() {
initView() initView()
......
...@@ -11,9 +11,30 @@ function uniCopyPlugin() { ...@@ -11,9 +11,30 @@ function uniCopyPlugin() {
return uni_cli_shared_1.uniViteCopyPlugin({ return uni_cli_shared_1.uniViteCopyPlugin({
targets: [ targets: [
{ {
src: slash_1.default(path_1.default.resolve(__dirname, '../../lib/template/*')), src: slash_1.default(path_1.default.resolve(__dirname, '../../lib/template/*.js')),
dest: process.env.UNI_OUTPUT_DIR, dest: process.env.UNI_OUTPUT_DIR,
}, },
{
src: slash_1.default(path_1.default.resolve(__dirname, '../../lib/template/*.png')),
dest: process.env.UNI_OUTPUT_DIR,
},
{
src: slash_1.default(path_1.default.resolve(__dirname, '../../lib/template/__uniappview.html')),
dest: process.env.UNI_OUTPUT_DIR,
transform(content) {
const { globalStyle } = uni_cli_shared_1.parsePagesJsonOnce(process.env.UNI_INPUT_DIR, process.env.UNI_PLATFORM);
const __uniConfig = {
globalStyle: {
rpxCalcMaxDeviceWidth: globalStyle.rpxCalcMaxDeviceWidth,
rpxCalcBaseDeviceWidth: globalStyle
.rpxCalcBaseDeviceWidth,
},
};
return content
.toString()
.replace('/*__uniConfig*/', `var __uniConfig = ${JSON.stringify(__uniConfig)}`);
},
},
{ {
src: slash_1.default(require.resolve('@dcloudio/uni-app-plus/dist/uni-app-view.umd.js')), src: slash_1.default(require.resolve('@dcloudio/uni-app-plus/dist/uni-app-view.umd.js')),
dest: process.env.UNI_OUTPUT_DIR, dest: process.env.UNI_OUTPUT_DIR,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>View</title> <title>View</title>
<link rel="stylesheet" href="app.css" /> <link rel="stylesheet" href="app.css" />
<script>/*__uniConfig*/</script>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
......
import path from 'path' import path from 'path'
import slash from 'slash' import slash from 'slash'
import { uniViteCopyPlugin } from '@dcloudio/uni-cli-shared' import { parsePagesJsonOnce, uniViteCopyPlugin } from '@dcloudio/uni-cli-shared'
export function uniCopyPlugin() { export function uniCopyPlugin() {
return uniViteCopyPlugin({ return uniViteCopyPlugin({
targets: [ targets: [
{ {
src: slash(path.resolve(__dirname, '../../lib/template/*')), src: slash(path.resolve(__dirname, '../../lib/template/*.js')),
dest: process.env.UNI_OUTPUT_DIR, dest: process.env.UNI_OUTPUT_DIR,
}, },
{
src: slash(path.resolve(__dirname, '../../lib/template/*.png')),
dest: process.env.UNI_OUTPUT_DIR,
},
{
src: slash(
path.resolve(__dirname, '../../lib/template/__uniappview.html')
),
dest: process.env.UNI_OUTPUT_DIR,
transform(content) {
const { globalStyle } = parsePagesJsonOnce(
process.env.UNI_INPUT_DIR,
process.env.UNI_PLATFORM
)
const __uniConfig = {
globalStyle: {
rpxCalcMaxDeviceWidth: (globalStyle as any).rpxCalcMaxDeviceWidth,
rpxCalcBaseDeviceWidth: (globalStyle as any)
.rpxCalcBaseDeviceWidth,
},
}
return content
.toString()
.replace(
'/*__uniConfig*/',
`var __uniConfig = ${JSON.stringify(__uniConfig)}`
)
},
},
{ {
src: slash( src: slash(
require.resolve('@dcloudio/uni-app-plus/dist/uni-app-view.umd.js') require.resolve('@dcloudio/uni-app-plus/dist/uni-app-view.umd.js')
......
...@@ -3,6 +3,7 @@ export function PolySymbol(name: string) { ...@@ -3,6 +3,7 @@ export function PolySymbol(name: string) {
} }
function hasRpx(str: string) { function hasRpx(str: string) {
str = str + ''
return str.indexOf('rpx') !== -1 || str.indexOf('upx') !== -1 return str.indexOf('rpx') !== -1 || str.indexOf('upx') !== -1
} }
......
...@@ -11,6 +11,7 @@ const setup_1 = require("./plugins/setup"); ...@@ -11,6 +11,7 @@ const setup_1 = require("./plugins/setup");
const ssr_1 = require("./plugins/ssr"); const ssr_1 = require("./plugins/ssr");
const utils_1 = require("./utils"); const utils_1 = require("./utils");
const handleHotUpdate_1 = require("./handleHotUpdate"); const handleHotUpdate_1 = require("./handleHotUpdate");
const transformIndexHtml_1 = require("./transformIndexHtml");
function initLogger({ logger, command }) { function initLogger({ logger, command }) {
if (command !== 'serve') { if (command !== 'serve') {
return; return;
...@@ -43,6 +44,7 @@ const UniH5Plugin = { ...@@ -43,6 +44,7 @@ const UniH5Plugin = {
initLogger(config); initLogger(config);
}, },
handleHotUpdate: handleHotUpdate_1.createHandleHotUpdate(), handleHotUpdate: handleHotUpdate_1.createHandleHotUpdate(),
transformIndexHtml: transformIndexHtml_1.createTransformIndexHtml(),
}; };
exports.default = [ exports.default = [
cssScoped_1.uniCssScopedPlugin(), cssScoped_1.uniCssScopedPlugin(),
......
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTransformIndexHtml = void 0;
const dist_1 = require("../../../uni-cli-shared/dist");
function createTransformIndexHtml() {
return function (html) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const manifestJson = dist_1.parseManifestJsonOnce(process.env.UNI_INPUT_DIR);
const title = ((_a = manifestJson.h5) === null || _a === void 0 ? void 0 : _a.title) || manifestJson.name || '';
return html.replace(/<title>(.*?)<\/title>/, `<title>${title}</title>`);
});
};
}
exports.createTransformIndexHtml = createTransformIndexHtml;
...@@ -12,6 +12,7 @@ import { uniSSRPlugin } from './plugins/ssr' ...@@ -12,6 +12,7 @@ import { uniSSRPlugin } from './plugins/ssr'
import { createDefine } from './utils' import { createDefine } from './utils'
import { createHandleHotUpdate } from './handleHotUpdate' import { createHandleHotUpdate } from './handleHotUpdate'
import { createTransformIndexHtml } from './transformIndexHtml'
function initLogger({ logger, command }: ResolvedConfig) { function initLogger({ logger, command }: ResolvedConfig) {
if (command !== 'serve') { if (command !== 'serve') {
...@@ -46,6 +47,7 @@ const UniH5Plugin: UniVitePlugin = { ...@@ -46,6 +47,7 @@ const UniH5Plugin: UniVitePlugin = {
initLogger(config) initLogger(config)
}, },
handleHotUpdate: createHandleHotUpdate(), handleHotUpdate: createHandleHotUpdate(),
transformIndexHtml: createTransformIndexHtml(),
} }
export default [ export default [
......
import { Plugin } from 'vite' import { Plugin } from 'vite'
import { VitePluginUniResolvedOptions } from '..'
import { parseManifestJsonOnce } from '../../../uni-cli-shared/dist' import { parseManifestJsonOnce } from '../../../uni-cli-shared/dist'
export function createTransformIndexHtml({ export function createTransformIndexHtml(): Plugin['transformIndexHtml'] {
inputDir,
}: VitePluginUniResolvedOptions): Plugin['transformIndexHtml'] {
return async function (html) { return async function (html) {
const manifestJson = parseManifestJsonOnce(inputDir) const manifestJson = parseManifestJsonOnce(process.env.UNI_INPUT_DIR)
const title = manifestJson.h5?.title || manifestJson.name || '' const title = manifestJson.h5?.title || manifestJson.name || ''
return html.replace(/<title>(.*?)<\/title>/, `<title>${title}</title>`) return html.replace(/<title>(.*?)<\/title>/, `<title>${title}</title>`)
} }
......
...@@ -797,6 +797,7 @@ function PolySymbol(name) { ...@@ -797,6 +797,7 @@ function PolySymbol(name) {
return Symbol(process.env.NODE_ENV !== "production" ? "[uni-app]: " + name : name); return Symbol(process.env.NODE_ENV !== "production" ? "[uni-app]: " + name : name);
} }
function hasRpx(str) { function hasRpx(str) {
str = str + "";
return str.indexOf("rpx") !== -1 || str.indexOf("upx") !== -1; return str.indexOf("rpx") !== -1 || str.indexOf("upx") !== -1;
} }
function rpx2px(str, replace = false) { function rpx2px(str, replace = false) {
...@@ -16754,7 +16755,7 @@ const sendSocketMessage = /* @__PURE__ */ defineAsyncApi(API_SEND_SOCKET_MESSAGE ...@@ -16754,7 +16755,7 @@ const sendSocketMessage = /* @__PURE__ */ defineAsyncApi(API_SEND_SOCKET_MESSAGE
const closeSocket = /* @__PURE__ */ defineAsyncApi(API_CLOSE_SOCKET, (options, { resolve, reject }) => { const closeSocket = /* @__PURE__ */ defineAsyncApi(API_CLOSE_SOCKET, (options, { resolve, reject }) => {
const socketTask = socketTasks[0]; const socketTask = socketTasks[0];
if (socketTask) { if (socketTask) {
callSocketTask(socketTask, "send", options, resolve, reject); callSocketTask(socketTask, "close", options, resolve, reject);
} else { } else {
reject("WebSocket is not connected"); reject("WebSocket is not connected");
} }
......
...@@ -10,7 +10,6 @@ import { createConfig } from './config' ...@@ -10,7 +10,6 @@ import { createConfig } from './config'
import { createConfigResolved } from './configResolved' import { createConfigResolved } from './configResolved'
import { createConfigureServer } from './configureServer' import { createConfigureServer } from './configureServer'
import { initExtraPlugins } from './utils' import { initExtraPlugins } from './utils'
import { createTransformIndexHtml } from './transformIndexHtml'
const debugUni = debug('vite:uni:plugin') const debugUni = debug('vite:uni:plugin')
...@@ -82,7 +81,6 @@ export default function uniPlugin( ...@@ -82,7 +81,6 @@ export default function uniPlugin(
config: createConfig(options, uniPlugins), config: createConfig(options, uniPlugins),
configResolved: createConfigResolved(options), configResolved: createConfigResolved(options),
configureServer: createConfigureServer(options), configureServer: createConfigureServer(options),
transformIndexHtml: createTransformIndexHtml(options),
}) })
plugins.push(...uniPlugins) plugins.push(...uniPlugins)
return plugins return plugins
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册