|
|
@@ -185,7 +185,7 @@
|
|
|
</div>
|
|
|
<div class="modal-footer">
|
|
|
<button type="button" class="btn btn-blank" data-dismiss="modal" @click="appVisible = false">取消</button>
|
|
|
- <button type="button" class="btn btn-blank btn-del" style="display: none;">删除</button>
|
|
|
+ <button type="button" class="btn btn-blank btn-del" v-show="!isAdd" @click="deleteAppInfo()">删除</button>
|
|
|
<button type="button" class="btn btn-default btn-submit" @click="saveAppInfo()">保存</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -194,7 +194,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import axios from 'axios'
|
|
|
+import _ from 'lodash'
|
|
|
+import axios from '@/assets/js/axios'
|
|
|
|
|
|
export default {
|
|
|
name: 'app-modal',
|
|
|
@@ -205,6 +206,7 @@ export default {
|
|
|
data () {
|
|
|
return {
|
|
|
appVisible: false,
|
|
|
+ isAdd: true,
|
|
|
appInfo: {}
|
|
|
}
|
|
|
},
|
|
|
@@ -216,36 +218,54 @@ export default {
|
|
|
this.$emit('update:visible', value)
|
|
|
},
|
|
|
data: function (value) {
|
|
|
- console.log(value)
|
|
|
- // Deep copy data to appInfo, when data changes.
|
|
|
- const temp = JSON.parse(JSON.stringify(value || {}))
|
|
|
- temp.type = temp.userControl ? 'control' : 'default'
|
|
|
+ value = value || {}
|
|
|
|
|
|
- // To implement two-way bindings, handle copy of prop before assign to
|
|
|
- // the data of component
|
|
|
- this.appInfo = temp
|
|
|
+ this.isAdd = !value.uid
|
|
|
|
|
|
+ // Set default values for app
|
|
|
+ const defaults = { type: value.userControl ? 'control' : 'default' }
|
|
|
+
|
|
|
+ // Set default values for new app info
|
|
|
+ if (!value.userControl && !value.uid) {
|
|
|
+ defaults.defaultUse = '1'
|
|
|
+ defaults.personalEnable = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ // To implement two-way bindings, deep copy data to appInfo, when data changes.
|
|
|
+ this.appInfo = _.defaults({}, value, defaults)
|
|
|
console.log('App type: ', this.appInfo.type)
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
saveAppInfo () {
|
|
|
- console.log(this.appInfo)
|
|
|
- if (this.appInfo.uid) {
|
|
|
- axios.put('/api/app//updateApp', this.appInfo)
|
|
|
- .then(response => {
|
|
|
- console.log(response.data)
|
|
|
- }).catch(response => {
|
|
|
- console.log(response)
|
|
|
- })
|
|
|
+ if (this.appInfo.type === 'control') {
|
|
|
+ this.appInfo.userControl = this.appInfo.userControl || ' '
|
|
|
+ }
|
|
|
+ const appInfo = _.omit(this.appInfo, 'type')
|
|
|
+ console.log(appInfo)
|
|
|
+
|
|
|
+ const success = () => {
|
|
|
+ this.$emit('success')
|
|
|
+ this.appVisible = false
|
|
|
+ }
|
|
|
+ const error = response => { this.showAddError({ message: response }) }
|
|
|
+
|
|
|
+ if (!this.isAdd) {
|
|
|
+ axios.put('/api/app//updateApp', appInfo).then(success).catch(error)
|
|
|
} else {
|
|
|
- axios.post('/api/app//addApp', this.appInfo)
|
|
|
- .then(response => {
|
|
|
- console.log(response.data)
|
|
|
- }).catch(response => {
|
|
|
- console.log(response)
|
|
|
- })
|
|
|
+ axios.post('/api/app//addApp', appInfo).then(success).catch(error)
|
|
|
}
|
|
|
+ },
|
|
|
+ deleteAppInfo () {
|
|
|
+ const uid = this.appInfo.uid || ''
|
|
|
+
|
|
|
+ const success = () => {
|
|
|
+ this.$emit('success')
|
|
|
+ this.appVisible = false
|
|
|
+ }
|
|
|
+ const error = response => { this.showAddError({ message: response }) }
|
|
|
+
|
|
|
+ axios.delete(`/api/app/${uid}/deleteApp`).then(success).catch(error)
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -255,6 +275,13 @@ export default {
|
|
|
showControl () {
|
|
|
return this.appInfo.type === 'control'
|
|
|
}
|
|
|
+ },
|
|
|
+ notifications: {
|
|
|
+ showAddError: {
|
|
|
+ title: 'Add Failed',
|
|
|
+ message: 'Failed to add app info',
|
|
|
+ type: 'error'
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|