Dataexport.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace modules\dataexport;
  3. use app\common\library\Menu;
  4. use app\admin\model\MenuRule;
  5. use ba\module\moduleException;
  6. use ba\module\Server;
  7. use FilesystemIterator;
  8. use RecursiveDirectoryIterator;
  9. use RecursiveIteratorIterator;
  10. use think\Exception;
  11. class Dataexport
  12. {
  13. private $uid = 'dataexport';
  14. public function install()
  15. {
  16. $pMenu = MenuRule::where('name', 'routine')->value('id');
  17. $menu = [
  18. [
  19. 'type' => 'menu',
  20. 'title' => '数据导出管理',
  21. 'name' => 'routine/dataexport',
  22. 'path' => 'routine/dataexport',
  23. 'icon' => 'fa fa-cloud-download',
  24. 'menu_type' => 'tab',
  25. 'component' => '/src/views/backend/routine/dataexport/index.vue',
  26. 'keepalive' => '1',
  27. 'pid' => $pMenu ? $pMenu : 0,
  28. 'children' => [
  29. ['type' => 'button', 'title' => '查看', 'name' => 'routine/dataexport/index'],
  30. ['type' => 'button', 'title' => '添加', 'name' => 'routine/dataexport/add'],
  31. ['type' => 'button', 'title' => '编辑', 'name' => 'routine/dataexport/edit'],
  32. ['type' => 'button', 'title' => '删除', 'name' => 'routine/dataexport/del'],
  33. ['type' => 'button', 'title' => '执行任务', 'name' => 'routine/dataexport/start'],
  34. ],
  35. ],
  36. [
  37. 'type' => 'menu',
  38. 'title' => '导出任务控制',
  39. 'name' => 'routine/dataexport/taskControl',
  40. 'path' => 'routine/dataexport/taskControl/:id',
  41. 'icon' => 'fa fa-cloud-download',
  42. 'menu_type' => 'tab',
  43. 'component' => '/src/views/backend/routine/dataexport/taskControl.vue',
  44. 'keepalive' => '1',
  45. 'extend' => 'add_rules_only',
  46. 'pid' => $pMenu ? $pMenu : 0,
  47. ]
  48. ];
  49. Menu::create($menu);
  50. }
  51. public function uninstall()
  52. {
  53. Menu::delete('routine/dataexport', true);
  54. Menu::delete('routine/dataexport/taskControl', true);
  55. }
  56. public function enable()
  57. {
  58. Menu::enable('routine/dataexport');
  59. Menu::enable('routine/dataexport/taskControl');
  60. }
  61. public function disable()
  62. {
  63. Menu::disable('routine/dataexport');
  64. Menu::disable('routine/dataexport/taskControl');
  65. }
  66. public function update()
  67. {
  68. // 兼容系统v1.1.2的语言包按需加载
  69. // 寻找安装时备份中的lang/pages文件,如果有,还原到lang/backend内而不是原位置
  70. $ebakDir = root_path() . 'modules' . DIRECTORY_SEPARATOR . 'ebak' . DIRECTORY_SEPARATOR;
  71. $zipFile = $ebakDir . $this->uid . '-install.zip';
  72. $zipDir = false;
  73. if (is_file($zipFile)) {
  74. try {
  75. $zipDir = Server::unzip($zipFile);
  76. } catch (moduleException|Exception $e) {
  77. // skip
  78. }
  79. }
  80. if ($zipDir) {
  81. $oldBaInputs = [
  82. path_transform('web\src\lang\pages\zh-cn\routine\dataexport.ts'),
  83. path_transform('web\src\lang\pages\en\routine\dataexport.ts')
  84. ];
  85. foreach ($oldBaInputs as $oldBaInput) {
  86. @unlink(root_path() . $oldBaInput);
  87. }
  88. foreach (
  89. $iterator = new RecursiveIteratorIterator(
  90. new RecursiveDirectoryIterator($zipDir, FilesystemIterator::SKIP_DOTS),
  91. RecursiveIteratorIterator::SELF_FIRST
  92. ) as $item
  93. ) {
  94. $ebakFile = path_transform($iterator->getSubPathName());
  95. if (!$item->isDir() && in_array($ebakFile, $oldBaInputs)) {
  96. $newFileName = str_replace(DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR, $ebakFile);
  97. copy($item, root_path() . $newFileName);
  98. }
  99. }
  100. }
  101. deldir($zipDir);
  102. del_empty_dir(root_path() . 'web/src/lang/pages/en');
  103. del_empty_dir(root_path() . 'web/src/lang/pages/zh-cn');
  104. }
  105. }