Просмотр исходного кода

fix(editor): update script after saving

Gerald 8 лет назад
Родитель
Сommit
dc22525241

+ 1 - 1
src/options/views/confirm.vue

@@ -24,7 +24,7 @@
       <div class="ellipsis confirm-msg" v-text="message"></div>
     </div>
     <div class="frame-block flex-auto pos-rel">
-      <vm-code class="abs-full" readonly v-model="code" :commands="commands" />
+      <vm-code class="abs-full" readonly :value="code" :commands="commands" />
     </div>
   </div>
 </template>

+ 10 - 9
src/options/views/edit/index.vue

@@ -19,7 +19,7 @@
       />
       <vm-settings
         v-show="nav === 'settings'" class="abs-full"
-        :script="script" :settings="settings"
+        :value="value" :settings="settings"
       />
     </div>
     <div class="frame-block" v-show="search.show">
@@ -105,7 +105,7 @@ function replaceAll(cm, state) {
 }
 
 export default {
-  props: ['script'],
+  props: ['value'],
   components: {
     VmCode,
     VmSettings,
@@ -161,10 +161,10 @@ export default {
   },
   mounted() {
     this.bindKeys();
-    (this.script.id ? sendMessage({
+    (this.value.id ? sendMessage({
       cmd: 'GetScript',
-      data: this.script.id,
-    }) : Promise.resolve(this.script))
+      data: this.value.id,
+    }) : Promise.resolve(this.value))
     .then(script => {
       const settings = {};
       settings.more = {
@@ -225,18 +225,19 @@ export default {
       return sendMessage({
         cmd: 'ParseScript',
         data: {
-          id: this.script.id,
+          id: this.value.id,
           code: this.code,
           // User created scripts MUST be marked `isNew` so that
-          // the backend is able to check namespace conflicts
-          isNew: !this.script.id,
+          // the backend is able to check namespace conflicts,
+          // otherwise the script with same namespace will be overridden
+          isNew: !this.value.id,
           message: '',
           custom: value,
           more,
         },
       })
       .then(script => {
-        this.script = script;
+        this.$emit('input', script);
         this.canSave = false;
       }, err => {
         showMessage({ text: err });

+ 6 - 6
src/options/views/edit/settings.vue

@@ -89,7 +89,7 @@
 import { i18n } from 'src/common';
 
 export default {
-  props: ['script', 'settings'],
+  props: ['value', 'settings'],
   computed: {
     custom() {
       return this.settings.custom || {};
@@ -98,12 +98,12 @@ export default {
       return this.settings.more || {};
     },
     placeholders() {
-      const { script } = this;
+      const { value } = this;
       return {
-        name: script.meta.name,
-        homepageURL: script.meta.homepageURL,
-        updateURL: script.meta.updateURL || i18n('hintUseDownloadURL'),
-        downloadURL: script.meta.downloadURL || script.lastInstallURL,
+        name: value.meta.name,
+        homepageURL: value.meta.homepageURL,
+        updateURL: value.meta.updateURL || i18n('hintUseDownloadURL'),
+        downloadURL: value.meta.downloadURL || value.lastInstallURL,
       };
     },
   },

+ 1 - 1
src/options/views/tab-installed.vue

@@ -15,7 +15,7 @@
       <item v-for="script in store.scripts" :key="script"
       :script="script" @edit="editScript" @move="moveScript"></item>
     </div>
-    <edit v-if="script" :script="script" @close="endEditScript"></edit>
+    <edit v-if="script" v-model="script" @close="endEditScript"></edit>
   </div>
 </template>