Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
菜鸟程序猿_c
uni-app
提交
1370b80f
U
uni-app
项目概览
菜鸟程序猿_c
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1370b80f
编写于
4月 19, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
差异文件
chore: merge
上级
b56b7031
b34fdbe6
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
212 addition
and
4 deletion
+212
-4
packages/uni-api/src/protocols/file/getFileInfo.ts
packages/uni-api/src/protocols/file/getFileInfo.ts
+10
-0
packages/uni-api/src/protocols/file/openDocument.ts
packages/uni-api/src/protocols/file/openDocument.ts
+10
-0
packages/uni-api/src/protocols/network/uploadFile.ts
packages/uni-api/src/protocols/network/uploadFile.ts
+7
-0
packages/uni-components/src/components/image/index.tsx
packages/uni-components/src/components/image/index.tsx
+157
-0
packages/uni-components/src/index.ts
packages/uni-components/src/index.ts
+1
-0
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+21
-2
packages/uni-h5/src/service/api/file/getFileInfo.ts
packages/uni-h5/src/service/api/file/getFileInfo.ts
+3
-1
packages/uni-h5/src/service/api/file/openDocument.ts
packages/uni-h5/src/service/api/file/openDocument.ts
+3
-1
未找到文件。
packages/uni-api/src/protocols/file/getFileInfo.ts
浏览文件 @
1370b80f
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
,
...
...
packages/uni-api/src/protocols/file/openDocument.ts
浏览文件 @
1370b80f
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
,
...
...
packages/uni-api/src/protocols/network/uploadFile.ts
浏览文件 @
1370b80f
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
||
{}
},
...
...
packages/uni-components/src/components/image/index.tsx
0 → 100644
浏览文件 @
1370b80f
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
}
packages/uni-components/src/index.ts
浏览文件 @
1370b80f
export
*
from
'
./components
'
export
{
useSubscribe
}
from
'
./helpers/useSubscribe
'
export
{
useCustomEvent
}
from
'
./helpers/useEvent
'
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
1370b80f
...
...
@@ -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
;
}
...
...
packages/uni-h5/src/service/api/file/getFileInfo.ts
浏览文件 @
1370b80f
...
...
@@ -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
)
packages/uni-h5/src/service/api/file/openDocument.ts
浏览文件 @
1370b80f
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录