file.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <div class="cl-menu-file">
  3. <el-row :gutter="10">
  4. <el-col :span="16">
  5. <el-select
  6. v-model="newValue"
  7. allow-create
  8. filterable
  9. clearable
  10. placeholder="请选择"
  11. >
  12. <el-option
  13. v-for="(item, index) in list"
  14. :key="index"
  15. :label="item.value"
  16. :value="item.value"
  17. >
  18. </el-option>
  19. </el-select>
  20. </el-col>
  21. <el-col :span="8">
  22. <div class="cl-menu-file__module">
  23. <span class="label">模块</span>
  24. <el-select
  25. v-model="form.moduleName"
  26. placeholder="选择模块"
  27. clearable
  28. filterable
  29. @change="onModuleChange"
  30. >
  31. <el-option
  32. v-for="(item, index) in moduleViews"
  33. :key="index"
  34. :label="item.label"
  35. :value="item.moduleName"
  36. >
  37. </el-option>
  38. </el-select>
  39. </div>
  40. </el-col>
  41. </el-row>
  42. </div>
  43. </template>
  44. <script>
  45. import { mapGetters } from "vuex";
  46. import { isEmpty } from "cl-admin/utils";
  47. const files = require.context("@/", true, /^.\/views.*(vue|js)/).keys();
  48. export default {
  49. name: "cl-menu-file",
  50. props: {
  51. value: [String]
  52. },
  53. inject: ["form"],
  54. data() {
  55. return {
  56. newValue: "",
  57. list: []
  58. };
  59. },
  60. computed: {
  61. ...mapGetters(["moduleViews"])
  62. },
  63. watch: {
  64. value: {
  65. immediate: true,
  66. handler(val) {
  67. this.newValue = val || "";
  68. }
  69. },
  70. newValue(val) {
  71. this.$emit("input", val);
  72. }
  73. },
  74. created() {
  75. this.list = files
  76. .filter((e) => {
  77. return !e.includes("components");
  78. })
  79. .map((e) => {
  80. return {
  81. value: e.substr(2)
  82. };
  83. });
  84. },
  85. methods: {
  86. async onModuleChange(val) {
  87. const { label, keepAlive, icon, path, component } = this.moduleViews.find(
  88. (e) => e.moduleName == val
  89. );
  90. if (label) {
  91. this.form.name = label;
  92. }
  93. if (path) {
  94. this.form.router = path;
  95. }
  96. if (icon) {
  97. this.form.icon = icon;
  98. }
  99. if (component) {
  100. let c = await component();
  101. this.form.viewPath = c.default.__file;
  102. }
  103. this.form.keepAlive = isEmpty(keepAlive) ? true : keepAlive;
  104. }
  105. }
  106. };
  107. </script>
  108. <style lang="scss" scoped>
  109. .cl-menu-file {
  110. width: 100%;
  111. /deep/ .el-select {
  112. width: 100%;
  113. }
  114. &__module {
  115. display: inline-flex;
  116. .label {
  117. width: 40px;
  118. text-align: right;
  119. margin-right: 10px;
  120. }
  121. }
  122. }
  123. </style>