FilePreview: Mobile Preview Control

更新时间:
2024-06-11
下载文档

FilePreview: Mobile Preview Control

The filePreview module provides an interface for applications to preview files. With "File Preview", you can get an open preview of a file.

Developers can determine whether these interfaces work in the EdgerOS mobile App environment through the following code:

edger.env().then(data => {
  if (data.env === 'edgerapp') {
    // We work in EdgerOS mobile App environment.
  }
}).catch(error => {
  console.error(error)
})

Functions

edger.filePreview.open(params)

Open file preview.

The parameters of the params method include:

  • files {Array} File items. The files attribute is a document file array, each document file item contains the following members:
    • id {String} Document file ID.
    • name {String} Document file name.
    • type {String} The type of document file. Optional values: doc | docx | ppt | pptx | pdf.
    • url {String} The url of document file.
    • createTime {String} The file of create time. Optional.
    • modifyTime {String} The url of modify time. Optional.
    • size {String} The url of live photo. Optional.
    • headers {Object} Media request headers. Optional.
  • positionFileId {string} The focus position of the player. Optional.
  • toolbar {Array} The toolbar items of the player. Optional. It can contain the following members:
    • icon {String} Toolbar icon.
    • code {String} Toolbar type code. Optional. Such as: drop | export | share | detail.
    • label {String} Toolbar title.
    • disabled {Boolean} Whether toolbar item is disabled. Optional.
  • Returns: {Promise}.

Example

const params = {
  id: 'xxx-xxx-xxxx-xxx',
  name: 'xxx',
  type: 'pdf',
  url: 'https://xxxxx'
};

edger.filePreview.open(params).then(() => {
  console.log("filePreview open successful");
}).catch((error) => {
  console.error(error);
});

async / await

async function filePreviewOpen() {
  try {
    await edger.filePreview.open(params);
  } catch (error) {
    console.error(error);
  }
}

edger.filePreview.toolbar(params)

Update toolbar.

The parameters of params include:

  • toolbar {Array} The toolbar items of the player. Optional. It can contain the following members:
    • icon {String} Toolbar icon.
    • code {String} Toolbar type code. Optional. Such as: drop | export | share | detail.
    • label {String} Toolbar title.
    • disabled {Boolean} Whether toolbar item is disabled. Optional.
  • Returns: {Promise}.

Example

const params = {
  toolbar: [
    { icon: 'details', code: 'details', label: '详情', disabled: false },
    { icon: 'trash', code: 'trash', label: '销毁', disabled: true },
    { icon: 'delete1', code: 'delete', label: '关闭', disabled: false }
  ]
}
edger.filePreview.toolbar(params).then((res) => {
  console.log('update toolbar successful.', res)
}).catch((error) => {
  console.error(error)
});

async / await

async function filePreviewToolbar() {
  try {
    const params = {
      toolbar: [
        { icon: 'details', code: 'details', label: '详情', disabled: false },
        { icon: 'trash', code: 'trash', label: '销毁', disabled: true },
        { icon: 'delete1', code: 'delete', label: '关闭', disabled: false }
      ]
    }
    await edger.filePreview.toolbar(params)
  } catch (error) {
    console.error(error)
  }
}

edger.filePreview.drop(params)

Drop file preview.

The parameters of params include:

  • id {String} File id.
  • Returns: {Promise}.

Example

edger.filePreview.drop({
  id: 'xxx-xxx-xxxx-xxx'
}).then((res) => {
  console.log('file preview drop successful.', res)
}).catch((error) => {
  console.error(error)
})

async / await

async function filePreviewDrop() {
  try {
    await edger.filePreview.drop({
      id: 'xxx-xxx-xxxx-xxx'
    })
  } catch (error) {
    console.error(error)
  }
}

edger.filePreview.close()

Close file preview.

  • Returns: {Promise}.

Example

edger.filePreview.close().then((res) => {
  console.log('caster close successful.', res)
}).catch((error) => {
  console.error(error)
})

async / await

async function filePreviewClose() {
  try {
    await edger.filePreview.close()
  } catch (error) {
    console.error(error)
  }
}

Events

The unified event listener provided by Web-SDK:

const listener = (payload) => {
  // Event handling...
}

// add listener
edger.filePreview.addEventListener('some-event', listener)

// or 
// onAction() is an alias of addEventListener().
edger.filePreview.onAction('some-event', listener)

// remove listener
edger.filePreview.removeEventListener('some-event', listener)

// remove all listeners
edger.filePreview.removeAllListeners()

status

This event will be generated when the media player changes.

  • Returns: {Object} A file preview object.

Get an object of result, the object includes:

  • status {String} The current state of the file preview. Optional values: open | close.

Example

edger.filePreview.addEventListener('status', (payload) => {
  const { status } = payload
  console.log("file preview status result:", status)
})

action

The toolbar click action of the file preview.

  • Returns: {Object} Get an object of result, the object includes:
    • id: {String} File id.
    • code. {String} Toolbar code.

Example

edger.filePreview.addEventListener('action', (payload) => {
  const { id, code } = payload
  console.log("file preview action result:", id, code)
})
文档内容是否对您有所帮助?
有帮助
没帮助