feat: demo perfect
parent
168a1dad0e
commit
0854a1166d
13
app.json
13
app.json
|
@ -31,7 +31,9 @@
|
|||
"pages/component/video/video",
|
||||
"pages/component/movable/movable",
|
||||
"pages/component/doc-web-view/doc-web-view",
|
||||
"pages/component/page-meta/page-meta"
|
||||
"pages/component/page-meta/page-meta",
|
||||
"pages/component/camera/camera",
|
||||
"pages/component/cover-view/cover-view"
|
||||
],
|
||||
"subpackages": [
|
||||
{
|
||||
|
@ -74,7 +76,14 @@
|
|||
"pages/upload-file/upload-file",
|
||||
"pages/voice/voice",
|
||||
"pages/previewMedia/index",
|
||||
"pages/getSelectedTextRange/index"
|
||||
"pages/getSelectedTextRange/index",
|
||||
"pages/fileToBase64/index",
|
||||
"pages/innerAudioContext/index",
|
||||
"pages/recorderManager/index",
|
||||
"pages/FileSystemManager/writefile",
|
||||
"pages/EventChannel/firstpage/index",
|
||||
"pages/EventChannel/secondpage/index",
|
||||
"pages/Accelerometer/index"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
// packageAPI/pages/Accelerometer/index.js
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
},
|
||||
emitstartAccelerometer () {
|
||||
wx.startAccelerometer({
|
||||
interval: 'game',
|
||||
complete (res) {
|
||||
console.log(res)
|
||||
}
|
||||
})
|
||||
},
|
||||
emitstopAccelerometer () {
|
||||
wx.stopAccelerometer()
|
||||
},
|
||||
AccelerometerChangeHandler () {
|
||||
console.log('~~AccelerometerChangeHandler~~')
|
||||
},
|
||||
emitonAccelerometerChange () {
|
||||
wx.onAccelerometerChange(this.AccelerometerChangeHandler)
|
||||
},
|
||||
emitoffAccelerometerChange () {
|
||||
wx.offAccelerometerChange(this.AccelerometerChangeHandler)
|
||||
}
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
<view>
|
||||
<button bindtap="emitstartAccelerometer">startAccelerometer</button>
|
||||
<button bindtap="emitstopAccelerometer">stopAccelerometer</button>
|
||||
<button bindtap="emitonAccelerometerChange">onAccelerometerChange</button>
|
||||
<button bindtap="emitoffAccelerometerChange">offAccelerometerChange</button>
|
||||
</view>
|
|
@ -0,0 +1 @@
|
|||
/* packageAPI/pages/Accelerometer/index.wxss */
|
|
@ -0,0 +1,60 @@
|
|||
let eventChannel = {}
|
||||
|
||||
Component({
|
||||
|
||||
/**
|
||||
* 组件的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
},
|
||||
|
||||
options: {
|
||||
multipleSlots: true,
|
||||
testoptions: '12skdfksdfk123'
|
||||
},
|
||||
|
||||
attached() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件的方法列表
|
||||
*/
|
||||
methods: {
|
||||
gotoDebugpage() {
|
||||
const self = this
|
||||
wx.navigateTo({
|
||||
url: '/packageAPI/pages/EventChannel/secondpage/index',
|
||||
events: {
|
||||
testevent: this.testeventcb
|
||||
},
|
||||
success(res) {
|
||||
console.log('debug wx.navigateTo success callback')
|
||||
eventChannel = res.eventChannel
|
||||
res.eventChannel.on('acceptDataFromOpenerPage', self.testevent)
|
||||
res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
|
||||
}
|
||||
})
|
||||
},
|
||||
testeventcb(e) {
|
||||
console.log('eventChannel debug: in first page testevent cb', e)
|
||||
setTimeout(() => {
|
||||
console.log(`.off('testevent'`)
|
||||
eventChannel.off('testevent', this.testeventcb)
|
||||
}, 5000)
|
||||
},
|
||||
testevent(data) {
|
||||
console.log('eventChannel debug: in first page acceptDataFromOpenerPage', data)
|
||||
setTimeout(() => {
|
||||
console.log(`.off('acceptDataFromOpenerPage')`)
|
||||
eventChannel.off('acceptDataFromOpenerPage')
|
||||
}, 5000)
|
||||
},
|
||||
reditotestpage() {
|
||||
wx.redirectTo({
|
||||
url: '/pages/testpage/index',
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
|
||||
<view>
|
||||
<view>
|
||||
跳转页面,再在新页面触发当前页testevent事件。触发后5s执行EventChannel.off注销事件
|
||||
</view>
|
||||
<button bindtap="gotoDebugpage">go to debugpage</button>
|
||||
</view>
|
|
@ -0,0 +1 @@
|
|||
/* pages/componentpage/index.wxss */
|
|
@ -0,0 +1,192 @@
|
|||
// pages/debugpage/index.js
|
||||
let secEventChannel
|
||||
let eventChannel
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
test: 123,
|
||||
testdata: [1,2,3]
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
console.log('debugpage onLoad', options)
|
||||
wx.onError((error) => {
|
||||
console.log('debugpage onError in api ', error)
|
||||
})
|
||||
eventChannel = this.getOpenerEventChannel()
|
||||
console.log(eventChannel)
|
||||
// eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});
|
||||
// eventChannel.emit('someEvent', {data: 'test'});
|
||||
// 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
|
||||
eventChannel.on('acceptDataFromOpenerPage', function(data) {
|
||||
console.log('eventChannel debug: in second page acceptDataFromOpenerPage', data)
|
||||
})
|
||||
setTimeout(() => {
|
||||
console.log('~~~~~~~~~~~~~~~')
|
||||
this.eventchannelemit()
|
||||
}, 10000)
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
},
|
||||
gototweetdetail: function () {
|
||||
wx.redirectTo({
|
||||
url: '/pages/testvideo/index?timelineId=d758d38c-0e2f-4f3d-82b6-57194980fbd2&fcid=@staff_staff1:000000.finogeeks.com&from=HOME',
|
||||
})
|
||||
},
|
||||
goTestvideo() {
|
||||
// wx.redirectTo({
|
||||
// url: '/pages/testvideo/index',
|
||||
// })
|
||||
wx.navigateTo({
|
||||
url: '/pages/testvideo/index',
|
||||
events: {
|
||||
testevent: this.testeventcb
|
||||
},
|
||||
success: (res) => {
|
||||
secEventChannel = res.eventChannel
|
||||
console.log('secEventChannel === eventChannel : ', secEventChannel === eventChannel)
|
||||
secEventChannel.emit('testevent', {a: 'secEventChannel'})
|
||||
}
|
||||
})
|
||||
},
|
||||
savefiletophone() {
|
||||
wx.downloadFile({
|
||||
url: 'https://kong.citics.com/citics/download/H5/xin_src/page/pdf_viewer/html/pdf_viewer.html?file=https%3A%2F%2Fkong.citics.com%2Fxtougu%2Fupload%2Fstock_relation%2FMR.pdf',
|
||||
success(res) {
|
||||
console.log(res);
|
||||
wx.saveFile({
|
||||
tempFilePath: res.tempFilePath,
|
||||
success: function (res) {
|
||||
console.log('打开文档成功')
|
||||
},
|
||||
complete(res) {
|
||||
console.log(res)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
// wx.chooseImage({
|
||||
// success: function(res) {
|
||||
// const tempFilePaths = res.tempFilePaths
|
||||
// console.log(res)
|
||||
// // wx.saveFile({
|
||||
// // tempFilePath: tempFilePaths[0],
|
||||
// // success (res) {
|
||||
// // const savedFilePath = res.savedFilePath
|
||||
// // console.log(res)
|
||||
// // }
|
||||
// // })
|
||||
// wx.openDocument({
|
||||
// filePath: tempFilePaths[0],
|
||||
// success: function (res) {
|
||||
// console.log('打开文档成功')
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
},
|
||||
dayinsdkversion() {
|
||||
const sdkversion = wx.getSystemInfoSync().SDKVersion;
|
||||
console.log(sdkversion)
|
||||
},
|
||||
getSupervisorInfo() {
|
||||
wx.getSuperviseInfo({
|
||||
success(res) {
|
||||
console.log('~~~getSuperviseInfo~~~ success ', res)
|
||||
},
|
||||
complete(res) {
|
||||
console.log('~~~getSuperviseInfo~~~ complete ', res)
|
||||
}
|
||||
})
|
||||
},
|
||||
gcp() {
|
||||
const cpage = getCurrentPages()
|
||||
console.log('debug getCurrentPages ', cpage)
|
||||
},
|
||||
eventcallback(opt) {
|
||||
console.log('debug eventcallback ', opt)
|
||||
},
|
||||
eventchannelon() {
|
||||
// const eventChannel = this.getOpenerEventChannel()
|
||||
console.log(eventChannel)
|
||||
eventChannel.on('testevent', this.eventcallback)
|
||||
},
|
||||
eventchanneloff() {
|
||||
// const eventChannel = this.getOpenerEventChannel()
|
||||
eventChannel.off('testevent', this.eventcallback)
|
||||
},
|
||||
eventchannelemit() {
|
||||
console.log('~~~~~~eventchannelemit~~~~~~~~~')
|
||||
// const eventChannel = this.getOpenerEventChannel()
|
||||
eventChannel.emit('testevent', {a: 'hahahhahh'})
|
||||
},
|
||||
eventchannelemitonceevvent() {
|
||||
// const eventChannel = this.getOpenerEventChannel()
|
||||
eventChannel.emit('acceptDataFromOpenerPage', {a: 'onceevent hahahhahh'})
|
||||
},
|
||||
testeventcb(e) {
|
||||
console.log('eventChannel debug: in second page testevent cb', e)
|
||||
|
||||
|
||||
|
||||
// setTimeout(() => {
|
||||
// console.log(`.off('testevent'`)
|
||||
// eventChannel.off('testevent', this.testeventcb)
|
||||
// }, 5000)
|
||||
},
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
|
||||
<view>
|
||||
<view>
|
||||
点击【eventChannel emit testevent】按钮触发上一页面testevent事件
|
||||
</view>
|
||||
<button bindtap="eventchannelemit">eventChannel emit testevent</button>
|
||||
|
||||
</view>
|
|
@ -0,0 +1 @@
|
|||
/* pages/debugpage/index.wxss */
|
|
@ -0,0 +1,526 @@
|
|||
// pages/writefile/index.js
|
||||
console.log('page 打印', wx.env.USER_DATA_PATH);
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
filePath: `${wx.env.USER_DATA_PATH}/d`,
|
||||
data: "",
|
||||
encoding: "utf-8",
|
||||
source: "",
|
||||
readencoding:"utf-8"
|
||||
|
||||
},
|
||||
|
||||
readFileFunc(path, encoding,position,length) {
|
||||
console.log('readFile encoding:', encoding, '; path:', path);
|
||||
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.readFile({
|
||||
filePath: path,
|
||||
encoding,
|
||||
position,
|
||||
length,
|
||||
|
||||
success(res) {
|
||||
console.log('readFile success:', res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('readFile fail:', res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
readFileSyncFunc(path, encoding, position, length) {
|
||||
console.log('readFileSync encoding:', encoding, '; path:', path);
|
||||
|
||||
const fs = wx.getFileSystemManager()
|
||||
|
||||
try {
|
||||
const res = fs.readFileSync(path, encoding,position,length)
|
||||
console.log('readFileSync res:', res)
|
||||
} catch (e) {
|
||||
console.log('readFileSync error:', e)
|
||||
}
|
||||
},
|
||||
|
||||
//同步
|
||||
writeFileSync() {
|
||||
const fs = wx.getFileSystemManager()
|
||||
try {
|
||||
const res = fs.writeFileSync(
|
||||
/* `${wx.env.USER_DATA_PATH}/hello.mp3` */null, "", 'utf8'
|
||||
)
|
||||
console.log('writeFileSync:', res)
|
||||
|
||||
} catch (e) {
|
||||
console.error('writeFileSync err:', e)
|
||||
}
|
||||
},
|
||||
|
||||
//异步文件测试
|
||||
writeFile() {
|
||||
console.log("打印地址", this.data.filePath)
|
||||
console.log("当前选中deta:",this.data.data)
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.writeFile({
|
||||
filePath: this.data.filePath,
|
||||
data: this.data.data,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeFile success:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
this.readFileSyncFunc(this.data.filePath, this.data.encoding,1,3)
|
||||
this.readFileFunc(this.data.filePath, this.data.encoding,2,4)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeFile fail:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
writeFileStartRange() {
|
||||
console.log("打印地址", this.data.filePath)
|
||||
console.log("当前选中deta:",this.data.data)
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.writeFile({
|
||||
filePath: this.data.filePath,
|
||||
data: this.data.data,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeFile success:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
this.readFileSyncFunc(this.data.filePath, this.data.encoding,3,1)
|
||||
this.readFileFunc(this.data.filePath, this.data.encoding,3,1)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeFile fail:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
writeFileLength0() {
|
||||
console.log("打印地址", this.data.filePath)
|
||||
console.log("当前选中deta:",this.data.data)
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.writeFile({
|
||||
filePath: this.data.filePath,
|
||||
data: this.data.data,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeFile success:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
this.readFileSyncFunc(this.data.filePath, this.data.encoding,2,0)
|
||||
this.readFileFunc(this.data.filePath, this.data.encoding,2,0)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeFile fail:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
writeFileLengthPoint() {
|
||||
console.log("打印地址", this.data.filePath)
|
||||
console.log("当前选中deta:",this.data.data)
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.writeFile({
|
||||
filePath: this.data.filePath,
|
||||
data: this.data.data,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeFile success:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
this.readFileSyncFunc(this.data.filePath, this.data.encoding,2,1.2)
|
||||
this.readFileFunc(this.data.filePath, this.data.encoding,2,1.2)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeFile fail:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
writeFileReadnoEncoding() {
|
||||
console.log("打印地址", this.data.filePath)
|
||||
console.log("当前选中deta:",this.data.data)
|
||||
const fs = wx.getFileSystemManager()
|
||||
const path = `${wx.env.USER_DATA_PATH}/nc`
|
||||
fs.writeFile({
|
||||
filePath:path,
|
||||
data: this.data.data,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeFile success:', res)
|
||||
console.log('写文件路径:' ,path),
|
||||
this.readFileSyncFunc(path)
|
||||
this.readFileFunc(path)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeFile fail:', res)
|
||||
// console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
writeFilePermission() {
|
||||
console.log("打印地址", this.data.filePath)
|
||||
console.log("当前选中deta:",this.data.data)
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.writeFile({
|
||||
|
||||
data: this.data.data,
|
||||
filePath:`${wx.env.USER_DATA_PATH}/d`,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeFile success:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
this.readFileSyncFunc(this.data.filePath, this.data.encoding,1,3)
|
||||
this.readFileFunc(this.data.filePath, this.data.encoding,2,4)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeFile fail:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
writeFileNotFound() {
|
||||
console.log("打印地址", this.data.filePath)
|
||||
console.log("当前选中deta:",this.data.data)
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.writeFile({
|
||||
|
||||
data: this.data.data,
|
||||
filePath:`${wx.env.USER_DATA_PATH}/d`,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeFile success:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
this.readFileSyncFunc(`${wx.env.USER_DATA_PATH}/dl`,this.data.encoding,1,3)
|
||||
this.readFileFunc(`${wx.env.USER_DATA_PATH}/dl`, this.data.encoding,2,4)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeFile fail:', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
base64File() {
|
||||
const path = `${wx.env.USER_DATA_PATH}/d`
|
||||
wx.fileToBase64({
|
||||
url: path,
|
||||
success: (res) => {
|
||||
console.log('fileToBase64 success: ', res)
|
||||
console.log(res.data)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('fileToBase64 fail: ', res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
saveFile() {
|
||||
wx.saveFile({
|
||||
filePath: `${wx.env.USER_DATA_PATH}/d`,
|
||||
success(res) {
|
||||
console.log("保存成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("保存失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
|
||||
downFile() {
|
||||
wx.downloadFile({
|
||||
url: `${wx.env.USER_DATA_PATH}/d`,
|
||||
success(res) {
|
||||
console.log("下载成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("下载失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
//图片
|
||||
writeImage() {
|
||||
const fs = wx.getFileSystemManager()
|
||||
const path = `${wx.env.USER_DATA_PATH}/a`
|
||||
fs.writeFile({
|
||||
filePath: path,
|
||||
data: this.data.data,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeImagSuccess', res)
|
||||
console.log(path)
|
||||
this.readFileSyncFunc(path, 'base64')
|
||||
this.readFileFunc(path, 'base64')
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeImageFail', res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
imagePreview() {
|
||||
wx.previewImage({
|
||||
urls: [`${wx.env.USER_DATA_PATH}/a`],
|
||||
success(res) {
|
||||
console.log("图片预览成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("图片预览失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
imageCompress() {
|
||||
|
||||
wx.compressImage({
|
||||
src: '`${wx.env.USER_DATA_PATH}/a`',
|
||||
|
||||
success(res) {
|
||||
console.log("图片压缩成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("图片压缩失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
imageSaveToPhotosAlbum() {
|
||||
wx.saveImageToPhotosAlbum({
|
||||
filePath: `${wx.env.USER_DATA_PATH}/a`,
|
||||
|
||||
success(res) {
|
||||
console.log("图片保存到相册成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("图片保存到相册失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
fileUpload() {
|
||||
|
||||
wx.uploadFile({
|
||||
filePath: `${wx.env.USER_DATA_PATH}/a`,
|
||||
name: 'file',
|
||||
url: 'https://finchat-mop-b.finogeeks.club/api/v1/mop/finstore/dev/files?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MjUxOTQyMjgsImZjaWQiOiI1ZmYzZDhmZWU3YzNiNTAwMDExYWQxMmEiLCJpYXQiOjE2MjUxODcwMjgsImlzcyI6Ijc1NWUxNnFrNVZLUnBlcWhKM1IySVFwV2NOdlQ5TWJOIn0.IQXdjiH5One-GVsU9E5KTze0fXJ7InJE-BrmcQs9yIc',
|
||||
success(res) {
|
||||
console.log("文件上传成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("文件上传失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
|
||||
//视频
|
||||
writeVideo() {
|
||||
const fs = wx.getFileSystemManager()
|
||||
const path = `${wx.env.USER_DATA_PATH}/b.mp4`
|
||||
fs.writeFile({
|
||||
filePath: path,
|
||||
data: this.data.data,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeVideo Success', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/b.mp4`)
|
||||
|
||||
this.readFileSyncFunc(path, 'base64')
|
||||
this.readFileFunc(path, 'base64')
|
||||
},
|
||||
|
||||
fail(res) {
|
||||
console.log('writeFail', res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
videoSaveToPhotosAlbum() {
|
||||
wx.saveVideoToPhotosAlbum({
|
||||
filePath: `${wx.env.USER_DATA_PATH}/b.mp4`,
|
||||
success(res) {
|
||||
console.log("视频保存到相册成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("视频保存到相册失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
mediaPreview() {
|
||||
wx.previewMedia({
|
||||
sources: [
|
||||
{
|
||||
"url": `${wx.env.USER_DATA_PATH}/b.mp4`,
|
||||
"type": "video"
|
||||
}
|
||||
],
|
||||
success(res) {
|
||||
console.log("视频播放成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("视频播放失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
videoPreview() {
|
||||
wx.previewVideo({
|
||||
|
||||
url: `${wx.env.USER_DATA_PATH}/b.mp4`,
|
||||
autoplay: true,
|
||||
success(res) {
|
||||
console.log('视频播放成功', res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('播放失败', res)
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
//语音
|
||||
writeAudio() {
|
||||
const fs = wx.getFileSystemManager()
|
||||
const path = `${wx.env.USER_DATA_PATH}/c.mp3`
|
||||
fs.writeFile({
|
||||
filePath: path,
|
||||
data: this.data.data,
|
||||
encoding: this.data.encoding,
|
||||
success: (res) => {
|
||||
console.log('writeAudio Success', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/c.mp3`)
|
||||
this.readFileSyncFunc(path, 'base64',10,13)
|
||||
this.readFileFunc(path, 'base64',20,15)
|
||||
},
|
||||
|
||||
fail(res) {
|
||||
console.log('writeFail', res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
innerAudioPlay() {
|
||||
const ctx = wx.createInnerAudioContext()
|
||||
ctx.src = `${wx.env.USER_DATA_PATH}/c.mp3`
|
||||
/* ctx.seek(20) */
|
||||
ctx.play()
|
||||
ctx.onPlay(() => {
|
||||
console.log('开始播放')
|
||||
})
|
||||
ctx.onError((res) => {
|
||||
console.log(res.errMsg)
|
||||
console.log(res.errCode)
|
||||
console.log(res)
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
voicePlay() {
|
||||
|
||||
wx.playVoice({
|
||||
filePath: `${wx.env.USER_DATA_PATH}/c.mp3`,
|
||||
success(res) {
|
||||
console.log("播放成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("播放失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
documentOpen() {
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.writeFile({
|
||||
filePath: `${wx.env.USER_DATA_PATH}/wd.doc`,
|
||||
data: this.data.data,
|
||||
encoding: this.data.encoding,
|
||||
success(res) {
|
||||
console.log('writeSuccess', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/wd.doc`)
|
||||
wx.openDocument({
|
||||
filePath: `${wx.env.USER_DATA_PATH}/wd.doc`,
|
||||
|
||||
success(res) {
|
||||
console.log("文件打开成功", res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log("文件打开失败", res)
|
||||
}
|
||||
})
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeFail', res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
writeFileArrayBuffer() {
|
||||
console.log("打印地址", this.data.filePath)
|
||||
/* console.log("打印data",this.data.data) */
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.writeFile({
|
||||
data: wx.base64ToArrayBuffer(this.data.data),
|
||||
filePath: `${wx.env.USER_DATA_PATH}/d`,
|
||||
encoding: this.data.encoding,
|
||||
success(res) {
|
||||
console.log('writeSuccess', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('writeFail', res)
|
||||
console.log(`${wx.env.USER_DATA_PATH}/d`)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
bindchangepath(e) {
|
||||
this.setData({
|
||||
filePath: e.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
bindchangeencoding(e) {
|
||||
this.setData({
|
||||
encoding: e.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
bindchangedata(e) {
|
||||
this.setData({
|
||||
data: e.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
})
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"usingComponents": {},
|
||||
"disableScroll":false
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,8 @@
|
|||
/* pages/writefile/index.wxss */
|
||||
|
||||
.title {
|
||||
padding: 10rpx 20rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
<view class="container">
|
||||
<template is="head" data="{{title: 'audio'}}"/>
|
||||
<view>
|
||||
<audio name="{{name}}" src="{{src}}" id="myAudio" controls ></audio>
|
||||
<audio name="{{name}}" src="{{src}}" id="myAudio" controls poster="./xuwei.jpg"></audio>
|
||||
|
||||
<button type="primary" bindtap="audioPlay">播放</button>
|
||||
<button type="primary" bindtap="audioPause">暂停</button>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1,94 @@
|
|||
// pages/filetobase64/index.js
|
||||
Page({
|
||||
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
base64:''
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
},
|
||||
downtrnas(e) {
|
||||
console.log(e.target.dataset.url)
|
||||
const self = this
|
||||
wx.downloadFile({
|
||||
url: e.target.dataset.url,
|
||||
success(res) {
|
||||
console.log('downloadfile success: ', res)
|
||||
wx.fileToBase64({
|
||||
url: res.tempFilePath,
|
||||
success(res) {
|
||||
console.log('fileToBase64 success: ', res)
|
||||
self.setData({
|
||||
base64:res.data
|
||||
})
|
||||
const ArrayBuffer=wx.base64ToArrayBuffer(res.data)
|
||||
console.log('print arrayBuffer',ArrayBuffer)
|
||||
},
|
||||
fail(res) {
|
||||
console.log('fileToBase64 fail: ', res)
|
||||
}
|
||||
})
|
||||
},
|
||||
fail(res) {
|
||||
console.log('downloadfile fail: ', res)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "二进制转base64"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<view>
|
||||
<button bindtap="downtrnas" data-url="https://www-cdn.finclip.com/images/logo.png">image</button>
|
||||
|
||||
<button bindtap="downtrnas" data-url="https://mp32.9ku.com/upload/128/2020/05/22/1004523.mp3">audio</button>
|
||||
|
||||
<button bindtap="downtrnas" data-url="https://vd3.bdstatic.com/mda-jgepmfmgjneifnyu/sc/mda-jgepmfmgjneifnyu.mp4?v_from_s=gz_videoui_4135&auth_key=1613963095-0-0-c41a503e270982b1ef8cab6f5d4514fa&bcevod_channel=searchbox_feed&pd=1&pt=3&abtest=">video</button>
|
||||
</view>
|
|
@ -0,0 +1 @@
|
|||
/* pages/filetobase64/index.wxss */
|
|
@ -17,6 +17,7 @@ Page({
|
|||
const that = this;
|
||||
try {
|
||||
const res = wx.getSystemInfoSync()
|
||||
console.log(res)
|
||||
console.log(res.model)
|
||||
console.log(res.pixelRatio)
|
||||
console.log(res.windowWidth)
|
||||
|
|
|
@ -64,6 +64,14 @@
|
|||
<input class="weui-input" type="text" disabled="{{true}}" placeholder="未获取" value="{{systemInfo.pixelRatio}}"></input>
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-cell weui-cell_input">
|
||||
<view class="weui-cell__hd">
|
||||
<view class="weui-label">SDKVersion</view>
|
||||
</view>
|
||||
<view class="weui-cell__bd">
|
||||
<input class="weui-input" type="text" disabled="{{true}}" placeholder="未获取" value="{{systemInfo.SDKVersion}}"></input>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="btn-area">
|
||||
<button type="primary" bindtap="getSystemInfo">获取手机系统信息</button>
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
//index.js
|
||||
//获取应用实例
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
volume:1,
|
||||
rate:1,
|
||||
},
|
||||
onLoad(){
|
||||
const innerAudioContext = wx.createInnerAudioContext()
|
||||
this.ctx = innerAudioContext
|
||||
console.log(innerAudioContext)
|
||||
|
||||
// innerAudioContext.playbackRate = 2.0
|
||||
|
||||
innerAudioContext.src = '/packageAPI/pages/innerAudioContext/mucis.mp3'
|
||||
// innerAudioContext.src = 'http://cdn.amathclass.cn/quesAudio/42fe780d-1607959109843.m4a'
|
||||
|
||||
const listener = ['Canplay', 'Ended', 'Pause', 'Play', 'Seeked', 'Seeking', 'Stop', 'TimeUpdate', 'Waiting']
|
||||
|
||||
listener.forEach(key=>{
|
||||
innerAudioContext['on'+key](()=>{
|
||||
console.log('on'+key)
|
||||
})
|
||||
})
|
||||
innerAudioContext.onError((res) => {
|
||||
console.log(res.errMsg)
|
||||
console.log(res)
|
||||
console.log(res.errCode)
|
||||
})
|
||||
// innerAudioContext.onWaiting((res)=>{
|
||||
// console.log(res)
|
||||
// console.log('wait')
|
||||
// })
|
||||
},
|
||||
onUnload() {
|
||||
this.ctx.destroy()
|
||||
console.log(this.ctx)
|
||||
},
|
||||
play(){
|
||||
this.ctx.play()
|
||||
// this.ctx.src = '/mucis.mp3'
|
||||
// this.ctx.autoplay = true
|
||||
},
|
||||
seek(){
|
||||
this.ctx.seek(60)
|
||||
},
|
||||
pause(){
|
||||
this.ctx.pause()
|
||||
},
|
||||
destroy(){
|
||||
this.ctx.destroy()
|
||||
console.log(this.ctx)
|
||||
},
|
||||
stop(){
|
||||
this.ctx.stop()
|
||||
},
|
||||
handleVolumeChange(e){
|
||||
this.setData({
|
||||
volume:e.detail.value
|
||||
})
|
||||
this.ctx.volume = this.data.volume
|
||||
},
|
||||
handleRateChange(e){
|
||||
this.setData({
|
||||
rate:e.detail.value
|
||||
})
|
||||
this.ctx.playbackRate = this.data.rate
|
||||
}
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<!--pages/index/index.wxml-->
|
||||
<view>
|
||||
<view>innerAudioContext</view>
|
||||
<button bindtap="play">play</button>
|
||||
<!-- <button bindtap="rate">rate</button> -->
|
||||
<button bindtap="pause">pause</button>
|
||||
<button bindtap="stop">stop</button>
|
||||
<button bindtap="seek">seek</button>
|
||||
<view>
|
||||
volume:
|
||||
<slider max='1' min='0' value='{{volume}}' step='0.1' show-value bindchange='handleVolumeChange'></slider>
|
||||
</view>
|
||||
<view>
|
||||
rate:
|
||||
<slider max='2' min='0.5' value='{{rate}}' step='0.1' show-value bindchange='handleRateChange'></slider>
|
||||
</view>
|
||||
<button bindtap="destroy">destroy</button>
|
||||
</view>
|
|
@ -0,0 +1,9 @@
|
|||
.button {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
.navigator-hover button{
|
||||
background-color: #DEDEDE;
|
||||
}
|
||||
.other-navigator-hover button{
|
||||
background-color: #DEDEDE;
|
||||
}
|
Binary file not shown.
|
@ -104,5 +104,20 @@ Page({
|
|||
console.log(res)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
previewImage() {
|
||||
wx.previewImage({
|
||||
urls: [
|
||||
'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1830914723,3154965800&fm=26&gp=0.jpg',
|
||||
'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091405991,859863778&fm=26&gp=0.jpg',
|
||||
],
|
||||
showmenu: true
|
||||
})
|
||||
},
|
||||
previewVideo() {
|
||||
wx.previewVideo({
|
||||
url: 'https://public-1251849568.cos.ap-guangzhou.myqcloud.com/homeSite/video/%E5%8A%9F%E8%83%BD%E4%BB%8B%E7%BB%8D.mp4',
|
||||
autoplay: false
|
||||
})
|
||||
},
|
||||
})
|
|
@ -3,4 +3,6 @@
|
|||
<view class="my-box">
|
||||
<button bindtap="previewMedia">previewMedia</button>
|
||||
<button bindtap="previewMedialocal">本地图片previewMedia</button>
|
||||
<button bindtap="previewVideo">previewVideo</button>
|
||||
<button bindtap="previewImage">previewImage</button>
|
||||
</view>
|
|
@ -0,0 +1,54 @@
|
|||
//index.js
|
||||
//获取应用实例
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
duration:'',
|
||||
stop:false,
|
||||
tempFilePath:''
|
||||
},
|
||||
onLoad(){
|
||||
this.ctx = wx.getRecorderManager()
|
||||
const listener = ['Error', 'FrameRecorded', 'InterruptionBegin', 'InterruptionEnd', 'Pause', 'Resume', 'Start']
|
||||
|
||||
listener.forEach(key=>{
|
||||
this.ctx['on'+key]((res)=>{
|
||||
console.log('on'+key,res)
|
||||
})
|
||||
})
|
||||
this.ctx.onStop(res=>{
|
||||
const {tempFilePath} = res
|
||||
console.log(res)
|
||||
this.setData({
|
||||
tempFilePath
|
||||
})
|
||||
})
|
||||
const innerAudioContext = wx.createInnerAudioContext()
|
||||
this.audioContext = innerAudioContext
|
||||
this.audioContext.onError(res=>{
|
||||
console.log(res.errMsg)
|
||||
console.log(res)
|
||||
console.log(res.errCode)
|
||||
})
|
||||
//
|
||||
},
|
||||
start(){
|
||||
this.ctx.start({"format":"mp3"})
|
||||
},
|
||||
resume(){
|
||||
this.ctx.resume()
|
||||
},
|
||||
pause(){
|
||||
this.ctx.pause()
|
||||
},
|
||||
stop(){
|
||||
this.ctx.stop()
|
||||
},
|
||||
play(){
|
||||
if(this.data.tempFilePath){
|
||||
this.audioContext.src = this.data.tempFilePath
|
||||
}
|
||||
this.audioContext.play()
|
||||
}
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<!--pages/index/index.wxml-->
|
||||
<view>
|
||||
<view>recorderManager</view>
|
||||
<button bindtap="start">start</button>
|
||||
<button bindtap="resume">resume</button>
|
||||
<button bindtap="pause">pause</button>
|
||||
<button bindtap="stop">stop</button>
|
||||
|
||||
<view>tempFilePath:{{tempFilePath}}</view>
|
||||
<button bindtap='play'>play</button>
|
||||
</view>
|
|
@ -0,0 +1,9 @@
|
|||
.button {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
.navigator-hover button{
|
||||
background-color: #DEDEDE;
|
||||
}
|
||||
.other-navigator-hover button{
|
||||
background-color: #DEDEDE;
|
||||
}
|
|
@ -159,12 +159,24 @@ Page({
|
|||
url: 'load-font-face/load-font-face'
|
||||
},
|
||||
{
|
||||
zh: 'previewMedia',
|
||||
zh: 'preview媒体预览',
|
||||
url: 'previewMedia/index'
|
||||
},
|
||||
{
|
||||
zh: 'getSelectedTextRange',
|
||||
url: 'getSelectedTextRange/index'
|
||||
},
|
||||
{
|
||||
zh: 'fileToBase64',
|
||||
url: 'fileToBase64/index'
|
||||
},
|
||||
{
|
||||
zh: 'innerAudioContext',
|
||||
url: 'innerAudioContext/index'
|
||||
},
|
||||
{
|
||||
zh: 'recorderManager',
|
||||
url: 'recorderManager/index'
|
||||
}
|
||||
]
|
||||
}, {
|
||||
|
@ -197,6 +209,33 @@ Page({
|
|||
// url: 'getRealtimeLogManager/index'
|
||||
// }
|
||||
],
|
||||
}, {
|
||||
id: 'route',
|
||||
name: '路由',
|
||||
pages: [
|
||||
{
|
||||
zh: 'EventChannel',
|
||||
url: 'EventChannel/firstpage/index'
|
||||
}
|
||||
],
|
||||
}, {
|
||||
id: 'file',
|
||||
name: '文件',
|
||||
pages: [
|
||||
{
|
||||
zh: 'FileSystemManager',
|
||||
url: 'FileSystemManager/writefile'
|
||||
}
|
||||
],
|
||||
}, {
|
||||
id: 'Accelerometer',
|
||||
name: '加速计',
|
||||
pages: [
|
||||
{
|
||||
zh: 'Accelerometer',
|
||||
url: 'Accelerometer/index'
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
isSetTabBarPage: false,
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
Page({
|
||||
data: {
|
||||
videoSrc: null,
|
||||
flash: 'on',
|
||||
devicePosition: 'back',
|
||||
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.ctx = wx.createCameraContext()
|
||||
},
|
||||
|
||||
|
||||
|
||||
takePhoto1() {
|
||||
|
||||
this.ctx.takePhoto({
|
||||
quality: 'low',
|
||||
success: (res) => {
|
||||
console.log(res);
|
||||
console.log("takePhoto success回调")
|
||||
this.setData({
|
||||
src: res.tempImagePath
|
||||
})
|
||||
wx.getImageInfo({
|
||||
src: res.tempImagePath,
|
||||
success(res){
|
||||
console.log(res)
|
||||
wx.showModal({
|
||||
title: "宽高比:"+res.width+"*"+res.height+'图片类型:'+res.type
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
fail(res){
|
||||
console.log(res)
|
||||
console.log("takePhoto fail回调")
|
||||
},
|
||||
complete(res){
|
||||
console.log(res)
|
||||
console.log("takePhoto complete回调")
|
||||
}
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
startRecord() {
|
||||
this.ctx.startRecord({
|
||||
success: (res) => {
|
||||
console.log('startRecord')
|
||||
},
|
||||
fail(res){
|
||||
console.log("开始录制失败的回调",res)
|
||||
},
|
||||
complete(res){
|
||||
console.log("开始录制完成",res)
|
||||
}
|
||||
})
|
||||
},
|
||||
stopRecord() {
|
||||
this.ctx.stopRecord({
|
||||
// compressed:true,
|
||||
|
||||
success: (res) => {
|
||||
console.log("停止录制",res)
|
||||
this.setData({
|
||||
src: res.tempThumbPath,
|
||||
videoSrc: res.tempVideoPath
|
||||
})
|
||||
wx.saveVideoToPhotosAlbum({
|
||||
filePath: res.tempVideoPath,
|
||||
success(res){
|
||||
console.log("保存到本地",res)
|
||||
},
|
||||
fail(res){
|
||||
console.log(0)
|
||||
console.log('保存失败',res)
|
||||
}
|
||||
})
|
||||
},
|
||||
fail(res){
|
||||
console.log("停止录制失败",res)
|
||||
},
|
||||
complete(res){
|
||||
console.log("完成录制",res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
saveVedio(){
|
||||
wx.saveVideoToPhotosAlbum({
|
||||
filePath: 'https://dn-odum9helk.qbox.me/spjc/1.mp4',
|
||||
success(res){
|
||||
console.log('http路径保存',res)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
cchangedevicePosition(e){
|
||||
this.setData({
|
||||
devicePosition: e.detail.value
|
||||
}),
|
||||
wx.showToast({
|
||||
title: "当前摄像头朝向: " + e.detail.value,
|
||||
icon: "none"
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
|
||||
bindchangeflash(e){
|
||||
this.setData({
|
||||
flash: e.detail.value
|
||||
}),
|
||||
wx.showToast({
|
||||
title: "当前闪关灯模式: " + e.detail.value,
|
||||
icon: "none"
|
||||
})
|
||||
},
|
||||
|
||||
bindinitdone(data) {
|
||||
console.log('bindinitdone camera初始化完成', data)
|
||||
},
|
||||
|
||||
bindstop(){
|
||||
console.log('摄像头在非正常终止时触发,如退出后台等情况----触发了')
|
||||
},
|
||||
binderror(){
|
||||
console.log('用户不允许使用摄像头时======触发了')
|
||||
},
|
||||
|
||||
bindscancode(){
|
||||
console.log("bindscancode扫码识别成功")
|
||||
},
|
||||
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<view class="page-body">
|
||||
<view class="page-body-wrapper">
|
||||
<camera
|
||||
mode="normal"
|
||||
resolution="medium"
|
||||
z-index="100"
|
||||
flash="{{flash}}"
|
||||
device-position="{{devicePosition}}"
|
||||
bindinitdone="bindinitdone"
|
||||
bindstop="bindstop"
|
||||
binderror="binderror"
|
||||
bindscancode="bindscancode"
|
||||
style="width: 50%; height: 300px;">
|
||||
|
||||
</camera>
|
||||
<cover-view style="background: red; position: absolute;top: 100px;width: 100%;">
|
||||
asdasd
|
||||
</cover-view>
|
||||
|
||||
|
||||
<view class="btn-area">
|
||||
<button type="primary" bindtap="takePhoto1">拍照</button>
|
||||
</view>
|
||||
<view class="btn-area">
|
||||
<button type="primary" bindtap="startRecord">开始录像</button>
|
||||
</view>
|
||||
<view class="btn-area">
|
||||
<button type="primary" bindtap="stopRecord">结束录像</button>
|
||||
</view>
|
||||
|
||||
<view>更新闪光灯模式</view>
|
||||
<radio-group bindchange='bindchangeflash'>
|
||||
<radio value="auto" >auto</radio>
|
||||
<radio value="on" checked>on</radio>
|
||||
<radio value="off">off</radio>
|
||||
<radio value="torch">torch</radio>
|
||||
</radio-group>
|
||||
|
||||
<view>更新摄像头朝向</view>
|
||||
<radio-group bindchange='cchangedevicePosition'>
|
||||
<radio value="back" checked>back</radio>
|
||||
<radio value="front" >front</radio>
|
||||
</radio-group>
|
||||
|
||||
<view class="preview-tips">预览</view>
|
||||
<image wx:if="{{src}}" mode="widthFix" src="{{src}}"></image>
|
||||
<video wx:if="{{videoSrc}}" class="video" src="{{videoSrc}}"></video>
|
||||
|
||||
</view>
|
||||
|
||||
<view><button bindtap="saveVedio">保存文件</button></view>
|
||||
</view>
|
|
@ -0,0 +1,9 @@
|
|||
.preview-tips {
|
||||
margin: 20rpx 0;
|
||||
}
|
||||
|
||||
.video {
|
||||
margin: 50px auto;
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
//index.js
|
||||
//获取应用实例
|
||||
const app = getApp()
|
||||
|
||||
|
||||
const loger = {
|
||||
success(res) {
|
||||
console.log(res)
|
||||
},
|
||||
fail(res) {
|
||||
console.log(res)
|
||||
},
|
||||
complete(res) {
|
||||
console.log('complete', res)
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
className: ''
|
||||
},
|
||||
onLoad() {
|
||||
let count = 0
|
||||
setInterval(() => {
|
||||
console.log('Set animate className', count)
|
||||
this.setData({
|
||||
className: count++ % 2 === 0 ? 'active' : ''
|
||||
})
|
||||
}, 7000)
|
||||
},
|
||||
onClick(e) {
|
||||
console.log('cover-view click', e)
|
||||
},
|
||||
onParentClick(e) {
|
||||
console.log('cover-view parent click', e)
|
||||
}
|
||||
})
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"usingComponents": {
|
||||
"title": "./title/index"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<!--index.wxml-->
|
||||
<view class="page-body" style="padding: 40px 0;">
|
||||
|
||||
<!-- relative -->
|
||||
<cover-view class="relative">
|
||||
<cover-view class="container" style="overflow: scroll;height: 400rpx">
|
||||
relative 定位, 内部可滚动(实机可,开发工具不可)
|
||||
<cover-view class="flex" bindtap="onParentClick" style="height: 300vh;">
|
||||
<cover-view class="flex-item text-1">文案1</cover-view>
|
||||
<cover-view class="flex-item text-2" bindtap="onClick">文案2可点击</cover-view>
|
||||
<cover-view class="flex-item text-3">超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3</cover-view>
|
||||
</cover-view>
|
||||
</cover-view>
|
||||
</cover-view>
|
||||
|
||||
<!-- absolute 定位 -->
|
||||
<cover-view class="absolute">
|
||||
<cover-view class="container">
|
||||
absolute 定位
|
||||
<cover-view class="flex">
|
||||
<cover-view class="flex-item text-1">文案1</cover-view>
|
||||
<cover-view class="flex-item text-2">文案2</cover-view>
|
||||
<cover-view class="flex-item text-3">文案3</cover-view>
|
||||
</cover-view>
|
||||
</cover-view>
|
||||
</cover-view>
|
||||
|
||||
<!-- fixed 定位 -->
|
||||
<cover-view class="fixed">
|
||||
<cover-view class="container">
|
||||
fixed 定位
|
||||
<cover-view class="flex">
|
||||
<cover-view class="flex-item text-1">文案1</cover-view>
|
||||
<cover-view class="flex-item text-2">文案2</cover-view>
|
||||
<cover-view class="flex-item text-3">超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3超长文案3</cover-view>
|
||||
</cover-view>
|
||||
</cover-view>
|
||||
</cover-view>
|
||||
|
||||
<!-- transform -->
|
||||
<cover-view class="transform">
|
||||
<cover-view class="content">
|
||||
transform 200 * 200
|
||||
</cover-view>
|
||||
</cover-view>
|
||||
|
||||
|
||||
<!-- animate -->
|
||||
<cover-view class="animate">
|
||||
<cover-view class="content {{className}}">
|
||||
animate
|
||||
</cover-view>
|
||||
</cover-view>
|
||||
|
||||
<cover-view>
|
||||
<cover-image src="https://img01.jituwang.com/201103/170742-201103210P292.jpg"></cover-image>
|
||||
<cover-image style="width: 600rpx;height: 600rpx;" src="./images/1.png"></cover-image>
|
||||
<cover-image style="width: 600rpx;height: 600rpx;" src="./images/2.gif"></cover-image>
|
||||
<cover-image style="width: 600rpx;height: 600rpx;" src="./images/3.jpg"></cover-image>
|
||||
<cover-image style="width: 600rpx;height: 600rpx;" src="./images/4.webp"></cover-image>
|
||||
<cover-image style="width: 600rpx;height: 600rpx;" src="https://media.missguided.com/s/missguided/O1448014_set/1/stone-longline-nylon-mac.webp?$category-page__grid--1x$%27"></cover-image>
|
||||
</cover-view>
|
||||
</view>
|
|
@ -0,0 +1,87 @@
|
|||
/**index.wxss**/
|
||||
|
||||
.page-body {
|
||||
height: 800vh;
|
||||
background-color: antiquewhite;
|
||||
}
|
||||
|
||||
.relative {
|
||||
height: 400rpx;
|
||||
margin-bottom: 120rpx;
|
||||
background: lightblue;
|
||||
}
|
||||
|
||||
.fixed {
|
||||
background: greenyellow;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.absolute {
|
||||
background: linear-gradient(#e66465, #9198e5);
|
||||
position: absolute;
|
||||
top: calc(60vh);
|
||||
left: calc(50% - 300rpx);
|
||||
}
|
||||
|
||||
.scroll-view {
|
||||
position: relative;
|
||||
height: 50vh;
|
||||
margin-top: 40vh;
|
||||
overflow: scroll;
|
||||
background-color: lightcoral;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display:flex;
|
||||
}
|
||||
|
||||
.flex-item{
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.text-1 {
|
||||
background-color: lightsteelblue;
|
||||
}
|
||||
|
||||
.text-2 {
|
||||
background-color: lightseagreen;
|
||||
}
|
||||
|
||||
.text-3 {
|
||||
background-color: lightpink;
|
||||
}
|
||||
|
||||
|
||||
.transform {
|
||||
height: 400rpx;
|
||||
margin-bottom: 120rpx;
|
||||
background-color: lightsalmon;
|
||||
}
|
||||
|
||||
.transform .content{
|
||||
height: 200rpx;
|
||||
width: 200rpx;
|
||||
transform: rotate(20deg) translate(120rpx, 70rpx) scale(1.5);
|
||||
background-color: lightskyblue;
|
||||
}
|
||||
|
||||
.animate {
|
||||
height: 400rpx;
|
||||
margin-bottom: 120rpx;
|
||||
background-color: lightcyan;
|
||||
transition: rotate 2s linear;
|
||||
}
|
||||
|
||||
.animate .content {
|
||||
height: 200rpx;
|
||||
width: 200rpx;
|
||||
background-color: lightskyblue;
|
||||
transition: transform 4s linear;
|
||||
}
|
||||
|
||||
.animate .content.active {
|
||||
transform: rotate(20deg) translate(120rpx, 70rpx) scale(1.5);
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
|
@ -0,0 +1,23 @@
|
|||
// components/title/index.js
|
||||
Component({
|
||||
/**
|
||||
* 组件的属性列表
|
||||
*/
|
||||
properties: {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件的方法列表
|
||||
*/
|
||||
methods: {
|
||||
|
||||
}
|
||||
})
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<!--components/title/index.wxml-->
|
||||
<map>
|
||||
<view>
|
||||
<slot></slot></view>
|
||||
</map>
|
|
@ -0,0 +1 @@
|
|||
/* components/title/index.wxss */
|
|
@ -12,7 +12,7 @@ Page({
|
|||
id: 'view',
|
||||
name: '视图容器',
|
||||
open: false,
|
||||
pages: ['view', 'scroll-view', 'swiper']
|
||||
pages: ['view', 'scroll-view', 'swiper', 'match-media', 'movable', 'cover-view']
|
||||
}, {
|
||||
id: 'content',
|
||||
name: '基础内容',
|
||||
|
@ -32,7 +32,7 @@ Page({
|
|||
id: 'media',
|
||||
name: '媒体组件',
|
||||
open: false,
|
||||
pages: ['image', 'video']
|
||||
pages: ['image', 'video', 'camera']
|
||||
}, {
|
||||
id: 'canvas',
|
||||
name: '画布',
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// index.js
|
||||
// 获取应用实例
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
motto: '',
|
||||
},
|
||||
// 事件处理函数
|
||||
bindViewTap() {
|
||||
wx.navigateTo({
|
||||
url: '../logs/logs'
|
||||
})
|
||||
},
|
||||
onResize(res){
|
||||
res.size.windowWidth // 新的显示区域宽度
|
||||
res.size.windowHeight // 新的显示区域高度
|
||||
console.log(res.size.windowWidth*res.size.windowWidth)
|
||||
wx.showToast({
|
||||
title:res.size.windowWidth*res.size.windowWidth
|
||||
})
|
||||
},
|
||||
onLoad() {
|
||||
this.setData({
|
||||
motto: 'hello world'
|
||||
})
|
||||
},
|
||||
click1(){
|
||||
wx.navigateTo({
|
||||
url: '/pages/indexApi/indexApi',
|
||||
})
|
||||
}
|
||||
})
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"usingComponents": {},
|
||||
"pageOrientation": "landscape"
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<!--index.ftml-->
|
||||
<view class="container">
|
||||
<view><button type="default" bindtap="click1">跳转到Api</button></view>
|
||||
<view><button type="default" bindtap="onResize">屏幕宽度</button></view>
|
||||
<match-media width="375">
|
||||
<button type="primary">宽度等于375时显示</button>
|
||||
</match-media>
|
||||
<match-media min-width="375">
|
||||
<button type="primary">宽度大于375时显示</button>
|
||||
</match-media>
|
||||
<match-media min-width="360">
|
||||
<button type="primary">宽度大于360时显示</button>
|
||||
</match-media>
|
||||
<match-media max-width="380">
|
||||
<button type="primary">宽度小于380时显示</button>
|
||||
</match-media>
|
||||
<match-media min-width="375" max-width="380">
|
||||
<button type="primary">宽度大于375并且小于380时显示</button>
|
||||
</match-media>
|
||||
<match-media height="842">
|
||||
<button type="primary">高度等于842时显示(不包含导航栏和状态栏)</button>
|
||||
</match-media>
|
||||
<match-media min-height="570">
|
||||
<button type="primary">高度大于570时显示</button>
|
||||
</match-media>
|
||||
<match-media max-height="680">
|
||||
<button type="primary">高度小于680时显示</button>
|
||||
</match-media>
|
||||
<match-media max-height="780">
|
||||
<button type="primary">高度小于780时显示</button>
|
||||
</match-media>
|
||||
<view>可爱爱</view>
|
||||
<button type="primary">一直显示1</button>
|
||||
<match-media max-height="380">
|
||||
<button type="primary">高度小于380时显示</button>
|
||||
</match-media>
|
||||
<button type="primary">一直显示2</button>
|
||||
<match-media orientation="landscape">
|
||||
<button type="primary">横屏时显示</button>
|
||||
</match-media>
|
||||
<match-media orientation="portrait">
|
||||
<button type="primary">竖屏时显示</button>
|
||||
</match-media>
|
||||
<button type="primary">一直显示</button>
|
||||
</view>
|
|
@ -0,0 +1,26 @@
|
|||
/**index.ftss**/
|
||||
.container{
|
||||
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
padding: 10rpx;
|
||||
background: gray;
|
||||
font-size: 14rpx;
|
||||
}
|
||||
|
||||
.container button{
|
||||
margin: 10rpx auto;
|
||||
}
|
||||
|
||||
progress{
|
||||
width: 100%;
|
||||
}
|
||||
.progress-box{
|
||||
display: flex;
|
||||
height: 25px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.progress-cancel{
|
||||
margin-left: 20px;
|
||||
}
|
|
@ -21,14 +21,14 @@
|
|||
"checkSiteMap": true,
|
||||
"uploadWithSourceMap": true,
|
||||
"compileHotReLoad": false,
|
||||
"useMultiFrameRuntime": false,
|
||||
"useMultiFrameRuntime": true,
|
||||
"useApiHook": true,
|
||||
"useApiHostProcess": true,
|
||||
"babelSetting": {
|
||||
"ignore": [],
|
||||
"disablePlugins": [],
|
||||
"outputPath": ""
|
||||
},
|
||||
"enableEngineNative": false,
|
||||
"bundle": false,
|
||||
"useIsolateContext": true,
|
||||
"useCompilerModule": true,
|
||||
|
|
Loading…
Reference in New Issue