ViewPages.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * +----------------------------------------------------------------------
  4. * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  5. * +----------------------------------------------------------------------
  6. * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  7. * +----------------------------------------------------------------------
  8. * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  9. * +----------------------------------------------------------------------
  10. * | Author: CRMEB Team <admin@crmeb.com>
  11. * +----------------------------------------------------------------------
  12. */
  13. namespace crmeb\services\crud;
  14. use think\helper\Str;
  15. /**
  16. * Class ViewPages
  17. * @author 等风来
  18. * @email 136327134@qq.com
  19. * @date 2023/4/1
  20. * @package crmeb\services\crud
  21. */
  22. class ViewPages extends Make
  23. {
  24. /**
  25. * @var string
  26. */
  27. protected $name = 'pages';
  28. /**
  29. * @return string
  30. * @author 等风来
  31. * @email 136327134@qq.com
  32. * @date 2023/4/4
  33. */
  34. protected function setBaseDir(): string
  35. {
  36. return 'pages' . DS . 'crud';
  37. }
  38. /**
  39. * @param string $name
  40. * @param string $path
  41. * @param array $options
  42. * @return false|mixed|void
  43. * @author 等风来
  44. * @email 136327134@qq.com
  45. * @date 2023/4/3
  46. */
  47. public function handle(string $name, string $path, array $options = [])
  48. {
  49. $field = $options['field'] ?? [];
  50. $columnStr = [];
  51. foreach ($field as $item) {
  52. $columnStr[] = "{\n\"title:\"{$item['name']},\n\"key:\"{$item['field']}\n}";
  53. }
  54. $this->value['auth'] = Str::snake($name);
  55. $this->value['content-vue'] = "\n" . implode(',', $columnStr);
  56. $this->value['pathApiJs'] = $options['pathApiJs'] ?? '';
  57. $this->value['nameCamel'] = Str::snake($name, '-');
  58. $this->basePath = $this->adminTemplatePath . 'pages';
  59. $this->fileMime = 'vue';
  60. return parent::handle($name, $path, $options); // TODO: Change the autogenerated stub
  61. }
  62. /**
  63. * @param string $path
  64. * @param string $name
  65. * @return string
  66. * @author 等风来
  67. * @email 136327134@qq.com
  68. * @date 2023/4/4
  69. */
  70. protected function getFilePathName(string $path, string $name): string
  71. {
  72. $path = ltrim(str_replace('\\', '/', $path), '/');
  73. return $this->getBasePath($path) . $name . '.' . $this->fileMime;
  74. }
  75. /**
  76. * @param string $type
  77. * @return string
  78. * @author 等风来
  79. * @email 136327134@qq.com
  80. * @date 2023/4/1
  81. */
  82. protected function getStub(string $type = '')
  83. {
  84. return __DIR__ . DS . 'stubs' . DS . 'view' .
  85. DS . 'pages' . DS . 'crud' .
  86. DS . 'index.stub';
  87. }
  88. }