face.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. export default {
  2. web: false,
  3. url: 'https://static-91daf9c1-d4fd-4f05-ac30-b930edfccc86.bspapp.com/bundle.js',
  4. init(callback = function() {}) {
  5. let _this = this;
  6. uni.downloadFile({
  7. url: _this.url,
  8. success: (res) => {
  9. if (res.statusCode === 200) {
  10. plus.io.resolveLocalFileSystemURL(res.tempFilePath, function(e) {
  11. plus.io.resolveLocalFileSystemURL("_doc/", function(ee) {
  12. ee.getDirectory('_doc/', {
  13. create: false,
  14. }, function(fileEntry) {
  15. plus.io.resolveLocalFileSystemURL('_doc/face.js',
  16. function(entry) {
  17. entry.remove();
  18. e.moveTo(ee, 'face.js');
  19. callback()
  20. },
  21. function() {
  22. e.moveTo(ee, 'face.js');
  23. callback()
  24. })
  25. })
  26. })
  27. })
  28. }
  29. }
  30. })
  31. },
  32. getis() {
  33. return new Promise((a, b) => {
  34. plus.io.resolveLocalFileSystemURL('_doc/face.js', function() {
  35. a(true)
  36. }, function() {
  37. a(false)
  38. })
  39. })
  40. },
  41. close() {
  42. plus.webview.close(this.web)
  43. },
  44. async open(obj = ['a', 'b', 'c'], callback = function() {}) {
  45. if (typeof obj !== 'object') {
  46. callback('参数有误不是 object');
  47. return false
  48. }
  49. let _this = this;
  50. if (await this.getis()) {
  51. plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) {
  52. fs.root.getFile('face.html', {
  53. create: true
  54. }, function(fileEntry) {
  55. fileEntry.file(function(file) {
  56. fileEntry.createWriter(function(writer) {
  57. writer.write(
  58. '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="IE=edge"></head><body></body></html>'
  59. );
  60. _this.web = plus.webview.create('_doc/face.html?type=' +
  61. JSON.stringify(obj), 999, {
  62. 'uni-app': 'none',
  63. "background": '#0000',
  64. "backButtonAutoControl": 'close',
  65. top: 0
  66. }, 'zoom-fade-out');
  67. _this.web.appendJsFile('_doc/face.js');
  68. _this.web.show();
  69. var _cc = setInterval(() => {
  70. if (plus.storage.getItem(
  71. "facetempuserimg")) {
  72. let img = plus.storage.getItem(
  73. "facetempuserimg");
  74. plus.storage.removeItem(
  75. "facetempuserimg");
  76. callback(img)
  77. };
  78. if (!plus.webview.getWebviewById('999')) {
  79. plus.storage.removeItem(
  80. "facetempuserimg");
  81. clearInterval(_cc)
  82. }
  83. }, 500)
  84. })
  85. })
  86. })
  87. })
  88. } else {
  89. callback('请先调用init 下载资源到手机')
  90. }
  91. }
  92. }