This commit is contained in:
2025-09-14 00:21:54 +08:00
commit d40b3bbd62
766 changed files with 36275 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
.image {
width: 100%;
height: 330px;
}
.page-body-info {
display: flex;
box-sizing: border-box;
padding: 15px;
height: 410px;
border-top: 1px solid var(--weui-FG-3);
border-bottom: 1px solid var(--weui-FG-3);
align-items: center;
justify-content: center;
}

View File

@@ -0,0 +1,133 @@
Page({
onShareAppMessage() {
return {
title: '文件',
path: 'packageAPI/pages/file/file',
};
},
onLoad() {
this.setData({
savedFilePath: xhs.getStorageSync('savedFilePath'),
});
},
data: {
tempFilePath: '',
savedFilePath: '',
dialog: {
hidden: true,
},
filePath: '',
fileType: '',
fileTypes: [
{
key: 'doc',
value: 'doc格式'
},
{
key: 'docx',
value: 'docx格式'
},
{
key: 'xls',
value: 'xls格式'
},
{
key: 'xlsx',
value: 'xlsx格式'
},
{
key: 'ppt',
value: 'ppt格式'
},
{
key: 'pptx',
value: 'pptx格式'
},
{
key: 'pdf',
value: 'pdf格式'
}
]
},
chooseImage() {
const that = this;
xhs.chooseImage({
count: 1,
success(res) {
that.setData({
tempFilePath: res.tempFilePaths[0],
});
},
});
},
saveFile() {
if (this.data.tempFilePath.length > 0) {
const that = this;
xhs.saveFile({
tempFilePath: this.data.tempFilePath,
success(res) {
that.setData({
savedFilePath: res.savedFilePath,
});
xhs.setStorageSync('savedFilePath', res.savedFilePath);
that.setData({
dialog: {
title: '保存成功',
content: '下次进入应用时,此文件仍可用',
hidden: false,
},
});
},
fail() {
that.setData({
dialog: {
title: '保存失败',
content: '应该是有 bug 吧',
hidden: false,
},
});
},
});
}
},
clear() {
xhs.setStorageSync('savedFilePath', '');
this.setData({
tempFilePath: '',
savedFilePath: '',
});
},
confirm() {
this.setData({
'dialog.hidden': true,
});
},
chooseFile() {
},
openFile() {
console.log(this.data.filePath);
console.log(this.data.fileType);
xhs.openDocument({
filePath: this.data.filePath,
fileType: this.data.fileType || undefined,
success(res) {
console.log(res);
},
fail(res) {
console.log(res);
}
});
},
handleFilePath(e) {
this.setData({ filePath: e.detail.value });
},
handleFileType(e) {
this.setData({ fileType: e.detail.value });
},
});

View File

@@ -0,0 +1,7 @@
{
"navigationBarTitleText": "文件",
"usingComponents": {
"showbox": "../../common/component/showbox/index",
"box": "../../common/component/container/index"
}
}

View File

@@ -0,0 +1,41 @@
<view class="container">
<showbox title="默认">
<box>
<!-- <view class="page-section">
<view class="page-body-info">
<block xhs:if="{{tempFilePath != ''}}">
<image src="{{tempFilePath}}" class="image" mode="aspectFit"></image>
</block>
<block xhs:if="{{tempFilePath === '' && savedFilePath != ''}}">
<image src="{{savedFilePath}}" class="image" mode="aspectFit"></image>
</block>
<block xhs:if="{{tempFilePath === '' && savedFilePath === ''}}">
<view class="image-plus image-plus-nb" bindtap="chooseImage">
<view class="image-plus-horizontal"></view>
<view class="image-plus-vertical"></view>
</view>
<view class="image-plus-text" bindtap="chooseFile">请选择文件</view>
</block>
</view>
<view class="btn-area">
<button type="primary" bindtap="saveFile">保存文件</button>
<button bindtap="clear">删除文件</button>
</view>
</view> -->
<view>文件类型:</view>
<view xhs:for="{{fileTypes}}">
{{item.key}}{{item.value}}
</view>
<view class="_ui-input">
<input placeholder="输入文件路径" value="{{filePath}}" bindinput="handleFilePath"/>
</view>
<view class="_ui-input">
<input placeholder="输入文件类型" value="{{fileType}}" bindinput="handleFileType"/>
</view>
<view>
<button class="_bcred" type="primary" bindtap="openFile">打开文件</button>
</view>
</box>
</showbox>
<modal title="{{dialog.title}}" hidden="{{dialog.hidden}}" no-cancel bindconfirm="confirm">{{dialog.content}}</modal>
</view>