This is an automated email from the ASF dual-hosted git repository.

min pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-ops.git


The following commit(s) were added to refs/heads/develop by this push:
     new fc3d82a  Add notify plugin (#154)
fc3d82a is described below

commit fc3d82a66b7409e907d3614e53e65f008278da32
Author: 马金凯 <[email protected]>
AuthorDate: Tue Oct 23 09:59:30 2018 +0800

    Add notify plugin (#154)
    
    * Add notify plugin
    
    * Add license and usage
---
 .../src/components/governance/AccessControl.vue    | 16 +-----
 .../src/components/public/notify/Snackbar.vue      | 38 +++++++++++++
 .../src/components/public/notify/index.js          | 62 ++++++++++++++++++++++
 dubbo-admin-frontend/src/main.js                   |  4 +-
 4 files changed, 104 insertions(+), 16 deletions(-)

diff --git a/dubbo-admin-frontend/src/components/governance/AccessControl.vue 
b/dubbo-admin-frontend/src/components/governance/AccessControl.vue
index e62a069..f8e2c3c 100644
--- a/dubbo-admin-frontend/src/components/governance/AccessControl.vue
+++ b/dubbo-admin-frontend/src/components/governance/AccessControl.vue
@@ -123,16 +123,6 @@
         </v-card-actions>
       </v-card>
     </v-dialog>
-
-    <v-snackbar v-model="snackbar.enable"
-                :color="snackbar.color">
-      {{ snackbar.text }}
-      <v-btn dark
-             flat
-             @click="snackbar.enable = false">
-        Close
-      </v-btn>
-    </v-snackbar>
   </v-container>
 </template>
 
@@ -277,11 +267,7 @@ export default {
       }).catch(error => this.showSnackbar('error', 
error.response.data.message))
     },
     showSnackbar (color, message) {
-      Object.assign(this.snackbar, {
-        enable: true,
-        color: color,
-        text: message
-      })
+      this.$notify(message, color)
       this.confirm.enable = false
       this.selected = []
     }
diff --git a/dubbo-admin-frontend/src/components/public/notify/Snackbar.vue 
b/dubbo-admin-frontend/src/components/public/notify/Snackbar.vue
new file mode 100644
index 0000000..ff4fd2d
--- /dev/null
+++ b/dubbo-admin-frontend/src/components/public/notify/Snackbar.vue
@@ -0,0 +1,38 @@
+<!--
+  - Licensed to the Apache Software Foundation (ASF) under one or more
+  - contributor license agreements.  See the NOTICE file distributed with
+  - this work for additional information regarding copyright ownership.
+  - The ASF licenses this file to You under the Apache License, Version 2.0
+  - (the "License"); you may not use this file except in compliance with
+  - the License.  You may obtain a copy of the License at
+  -
+  -     http://www.apache.org/licenses/LICENSE-2.0
+  -
+  - Unless required by applicable law or agreed to in writing, software
+  - distributed under the License is distributed on an "AS IS" BASIS,
+  - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  - See the License for the specific language governing permissions and
+  - limitations under the License.
+  -->
+<template>
+  <v-snackbar v-model="show"
+              :color="color">
+    {{ text }}
+    <v-btn dark
+           flat
+           @click="show = false">
+      Close
+    </v-btn>
+  </v-snackbar>
+</template>
+<script>
+export default {
+  data () {
+    return {
+      show: false,
+      color: '',
+      text: ''
+    }
+  }
+}
+</script>
diff --git a/dubbo-admin-frontend/src/components/public/notify/index.js 
b/dubbo-admin-frontend/src/components/public/notify/index.js
new file mode 100644
index 0000000..554237a
--- /dev/null
+++ b/dubbo-admin-frontend/src/components/public/notify/index.js
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ *  he License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+Usage:
+  main.js
+    import Notify from './components/public/notify'
+    Vue.use(Notify)
+
+  Some.vue:
+    this.$notify(message, color)
+    this.$notify.error(message)
+    this.$notify.success(message)
+    this.$notify.info(message)
+ */
+import Snackbar from './Snackbar.vue'
+
+const Notify = {}
+
+Notify.install = function (Vue) {
+  const SnackbarConstructor = Vue.extend(Snackbar)
+  const instance = new SnackbarConstructor()
+  let vm = instance.$mount()
+  document.querySelector('body').appendChild(vm.$el)
+
+  Vue.prototype.$notify = (text, color) => {
+    instance.text = text
+    instance.color = color
+    instance.show = true
+  }
+  Vue.prototype.$notify.error = text => {
+    instance.text = text
+    instance.color = 'error'
+    instance.show = true
+  }
+  Vue.prototype.$notify.success = text => {
+    instance.text = text
+    instance.color = 'success'
+    instance.show = true
+  }
+  Vue.prototype.$notify.info = text => {
+    instance.text = text
+    instance.color = 'info'
+    instance.show = true
+  }
+}
+
+export default Notify
diff --git a/dubbo-admin-frontend/src/main.js b/dubbo-admin-frontend/src/main.js
index 3f0a668..c2728b7 100644
--- a/dubbo-admin-frontend/src/main.js
+++ b/dubbo-admin-frontend/src/main.js
@@ -22,9 +22,11 @@ import App from './App'
 import router from './router'
 import Vuetify from 'vuetify'
 import 'vuetify/dist/vuetify.min.css'
-import {store} from './store'
+import { store } from './store'
+import Notify from './components/public/notify'
 
 Vue.use(Vuetify)
+Vue.use(Notify)
 
 Vue.config.productionTip = false
 

Reply via email to