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

chore: merge

import { getRealPath } from '@dcloudio/uni-platform'
export const API_GET_FILE_INFO = 'getFileInfo'
export type API_TYPE_GET_FILE_INFO = typeof uni.getFileInfo
export const GetFileInfoOptions: ApiOptions<API_TYPE_GET_FILE_INFO> = {
formatArgs: {
filePath(filePath, params) {
params.filePath = getRealPath(filePath)
},
},
}
export const GetFileInfoProtocol: ApiProtocol<API_TYPE_GET_FILE_INFO> = {
filePath: {
type: String,
......
import { getRealPath } from '@dcloudio/uni-platform'
export const API_OPEN_DOCUMENT = 'openDocument'
export type API_TYPE_OPEN_DOCUMENT = typeof uni.openDocument
export const OpenDocumentOptions: ApiOptions<API_TYPE_OPEN_DOCUMENT> = {
formatArgs: {
filePath(filePath, params) {
params.filePath = getRealPath(filePath)
},
},
}
export const OpenDocumentProtocol: ApiProtocol<API_TYPE_OPEN_DOCUMENT> = {
filePath: {
type: String,
......
import { getRealPath } from '@dcloudio/uni-platform'
export const API_UPLOAD_FILE = 'uploadFile'
export type API_TYPE_UPLOAD_FILE = typeof uni.uploadFile
export const UploadFileOptions: ApiOptions<API_TYPE_UPLOAD_FILE> = {
formatArgs: {
filePath(filePath, params) {
if (filePath) {
params.filePath = getRealPath(filePath)
}
},
header(value: Record<string, any>, params: Record<string, any>) {
params.header = value || {}
},
......
import {
ref,
defineComponent,
computed,
Ref,
watchEffect,
watch,
onMounted,
reactive,
} from 'vue'
import { getRealPath } from '@dcloudio/uni-platform'
import { useCustomEvent } from '../../helpers/useEvent'
import ResizeSensor from '../resize-sensor/index.vue'
export default /*#__PURE__*/ defineComponent({
name: 'Image',
props: {
src: {
type: String,
default: '',
},
mode: {
type: String,
default: 'scaleToFill',
},
lazyLoad: {
type: [Boolean, String],
default: false,
},
draggable: {
type: Boolean,
default: true,
},
},
setup(props, { emit }) {
const rootRef = ref(null)
const src = useImageSrc(props)
const modeStyle = useImageMode(props, src)
return () => {
const { mode } = props
const imgSrc = src.value
return (
<uni-image ref={rootRef}>
<div ref="content" style={modeStyle.value} />
{imgSrc && <img src={imgSrc} />}
{(mode === 'widthFix' || mode === 'heightFix') && <ResizeSensor />}
</uni-image>
)
}
},
})
function useImageData() {
return reactive({
originalWidth: 0,
originalHeight: 0,
originalStyle: { width: '', height: '' },
src: '',
})
}
function loadImage(src: string) {}
function useImageSrc(props: { src: string }) {
const src = computed(() => getRealPath(props.src))
watch(
() => props.src,
() => {
// loadImage
}
)
return src
}
const IMAGE_MODES = {
aspectFit: ['contain', 'center center'],
aspectFill: ['cover', 'center center'],
widthFix: ['100% 100%'],
heightFix: ['100% 100%'],
top: [, 'center top'],
bottom: [, 'center bottom'],
center: [, 'center center'],
left: [, 'left center'],
right: [, 'right center'],
'top left': [, 'left top'],
'top right': [, 'right top'],
'bottom left': [, 'left bottom'],
'bottom right': [, 'right bottom'],
}
function useImageMode(props: { mode: string }, rootRef: Ref, src: Ref<string>) {
const style = computed(() => {
let size = 'auto'
let position = ''
const opts = IMAGE_MODES[props.mode as keyof typeof IMAGE_MODES]
if (opts) {
} else {
size = '100% 100%'
position = '0% 0%'
}
const srcVal = src.value
return `background-image:${
srcVal ? 'url("' + srcVal + '")' : 'none'
};background-position:${position};background-size:${size};background-repeat:no-repeat;`
})
const ratio = ref(0)
const origWidth = ref(0)
const origHeight = ref(0)
onMounted(() => {
const rootVal = rootRef.value as HTMLElement
const style = rootVal.style
origWidth.value = Number(style.width) || 0
origHeight.value = Number(style.height) || 0
})
watch(
() => props.mode,
() => {
// const { mode } = props
// fixSize(rootRef.value as HTMLElement, props.mode)
// TODO
// resetSize()
}
)
return style
}
function fixNumber(num: number) {
// fix: 解决 Chrome 浏览器上某些情况下导致 1px 缝隙的问题
if (typeof navigator && navigator.vendor === 'Google Inc.' && num > 10) {
num = Math.round(num / 2) * 2
}
return num
}
function fixSize(el: HTMLElement, mode: string, ratio: number) {
if (!ratio) {
return
}
const rect = el.getBoundingClientRect()
if (mode === 'widthFix') {
const width = rect.width
if (width) {
el.style.height = fixNumber(width / ratio) + 'px'
}
} else if (mode === 'heightFix') {
const height = rect.height
if (height) {
el.style.width = fixNumber(height * ratio) + 'px'
}
}
}
function resetSize(el: HTMLElement, width: string, height: string) {
const style = el.style
style.width = width
style.height = height
}
export * from './components'
export { useSubscribe } from './helpers/useSubscribe'
export { useCustomEvent } from './helpers/useEvent'
......@@ -4550,6 +4550,13 @@ const API_REMOVE_STORAGE = "removeStorage";
const RemoveStorageProtocol = GetStorageProtocol;
const RemoveStorageSyncProtocol = GetStorageSyncProtocol;
const API_GET_FILE_INFO = "getFileInfo";
const GetFileInfoOptions = {
formatArgs: {
filePath(filePath, params) {
params.filePath = getRealPath(filePath);
}
}
};
const GetFileInfoProtocol = {
filePath: {
type: String,
......@@ -4557,6 +4564,13 @@ const GetFileInfoProtocol = {
}
};
const API_OPEN_DOCUMENT = "openDocument";
const OpenDocumentOptions = {
formatArgs: {
filePath(filePath, params) {
params.filePath = getRealPath(filePath);
}
}
};
const OpenDocumentProtocol = {
filePath: {
type: String,
......@@ -4797,6 +4811,11 @@ const DownloadFileProtocol = {
const API_UPLOAD_FILE = "uploadFile";
const UploadFileOptions = {
formatArgs: {
filePath(filePath, params) {
if (filePath) {
params.filePath = getRealPath(filePath);
}
},
header(value, params) {
params.header = value || {};
},
......@@ -11078,11 +11097,11 @@ const getFileInfo = defineAsyncApi(API_GET_FILE_INFO, ({filePath}, {resolve, rej
}).catch((err) => {
reject(String(err));
});
}, GetFileInfoProtocol);
}, GetFileInfoProtocol, GetFileInfoOptions);
const openDocument = defineAsyncApi(API_OPEN_DOCUMENT, ({filePath}, {resolve}) => {
window.open(filePath);
return resolve();
}, OpenDocumentProtocol);
}, OpenDocumentProtocol, OpenDocumentOptions);
function getServiceAddress() {
return window.location.protocol + "//" + window.location.host;
}
......
......@@ -3,6 +3,7 @@ import {
API_GET_FILE_INFO,
API_TYPE_GET_FILE_INFO,
GetFileInfoProtocol,
GetFileInfoOptions,
} from '@dcloudio/uni-api'
import { urlToFile } from '../../../helpers/file'
......@@ -20,5 +21,6 @@ export const getFileInfo = defineAsyncApi<API_TYPE_GET_FILE_INFO>(
reject(String(err))
})
},
GetFileInfoProtocol
GetFileInfoProtocol,
GetFileInfoOptions
)
......@@ -3,6 +3,7 @@ import {
API_TYPE_OPEN_DOCUMENT,
defineAsyncApi,
OpenDocumentProtocol,
OpenDocumentOptions,
} from '@dcloudio/uni-api'
export const openDocument = defineAsyncApi<API_TYPE_OPEN_DOCUMENT>(
......@@ -11,5 +12,6 @@ export const openDocument = defineAsyncApi<API_TYPE_OPEN_DOCUMENT>(
window.open(filePath)
return resolve()
},
OpenDocumentProtocol
OpenDocumentProtocol,
OpenDocumentOptions
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册