gaoshp
2024-04-27 e1947c8638faedf07e2298a57a850f711196845f
机器组
已修改3个文件
163 ■■■■■ 文件已修改
src/utils/request.js 70 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/tpm/MachineGroup.vue 80 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/tpm/machine-management.vue 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/request.js
@@ -13,10 +13,10 @@
    (config) => {
        let token = tool.cookie.get("TOKEN");
        config.headers['Authorization'] = 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
        if(token){
        if (token) {
            config.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token
        }
        if(!sysConfig.REQUEST_CACHE && config.method == 'get'){
        if (!sysConfig.REQUEST_CACHE && config.method == 'get') {
            config.params = config.params || {};
            // config.params['_'] = new Date().getTime();
        }
@@ -49,7 +49,7 @@
                    message: error.response.data.message || "Status:500,服务器发生错误!"
                });
            } else if (error.response.status == 401) {
                if(!MessageBox_401_show){
                if (!MessageBox_401_show) {
                    MessageBox_401_show = true
                    ElMessageBox.confirm('当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。', '无权限访问', {
                        type: 'error',
@@ -61,8 +61,8 @@
                            done()
                        }
                    }).then(() => {
                        router.replace({path: '/login'});
                    }).catch(() => {})
                        router.replace({ path: '/login' });
                    }).catch(() => { })
                }
            } else {
                ElNotification.error({
@@ -81,16 +81,16 @@
    }
);
function qsStringify(obj) {
  return Object.keys(obj)
    .map(key => {
      if (Array.isArray(obj[key])) {
        return obj[key]
          .map(arrayValue => `${encodeURIComponent(key)}=${encodeURIComponent(arrayValue)}`)
          .join('&');
      }
      return `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
    })
    .join('&');
    return Object.keys(obj)
        .map(key => {
            if (Array.isArray(obj[key])) {
                return obj[key]
                    .map(arrayValue => `${encodeURIComponent(key)}=${encodeURIComponent(arrayValue)}`)
                    .join('&');
            }
            return `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
        })
        .join('&');
}
var http = {
@@ -100,7 +100,7 @@
     * @param  {object} params 请求参数
     * @param  {object} config 参数
     */
    get: function(url, params={}, config={}) {
    get: function (url, params = {}, config = {}) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'get',
@@ -120,7 +120,7 @@
     * @param  {object} data 请求参数
     * @param  {object} config 参数
     */
    post: function(url, data={}, config={}) {
    post: function (url, data = {}, config = {}) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'post',
@@ -130,12 +130,12 @@
            }).then((response) => {
                resolve(response.data);
            }).catch((error) => {
                if(error.status == 400) {
                if (error.status == 400) {
                    ElMessage({
                        message: error.data.msg,
                        type: 'warning',
                     })
                }else {
                        message: error.data.msg,
                        type: 'warning',
                    })
                } else {
                    reject(error);
                }
            })
@@ -146,13 +146,13 @@
     * @param  {object} data 请求参数
     * @param  {object} config 参数
     */
     postJ: function(url, data={}, config={}) {
    postJ: function (url, data = {}, config = {}) {
        return new Promise((resolve, reject) => {
            console.log(qsStringify(data))
            axios({
                method: 'post',
                url: url,
                headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
                headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
                data: qsStringify(data),
                ...config
            }).then((response) => {
@@ -167,7 +167,7 @@
     * @param  {object} data 请求参数
     * @param  {object} config 参数
     */
    put: function(url, data={}, config={}) {
    put: function (url, data = {}, config = {}) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'put',
@@ -187,7 +187,7 @@
     * @param  {object} data 请求参数
     * @param  {object} config 参数
     */
    patch: function(url, data={}, config={}) {
    patch: function (url, data = {}, config = {}) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'patch',
@@ -207,7 +207,7 @@
     * @param  {object} data 请求参数
     * @param  {object} config 参数
     */
    delete: function(url, data={}, config={}) {
    delete: function (url, data = {}, config = {}) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'delete',
@@ -217,12 +217,12 @@
            }).then((response) => {
                resolve(response.data);
            }).catch((error) => {
                if(error.status == 400) {
                if (error.status == 400) {
                    ElMessage({
                        message: error.data.msg,
                        type: 'warning',
                     })
                }else {
                        message: error.data.msg,
                        type: 'warning',
                    })
                } else {
                    reject(error);
                }
            })
@@ -233,19 +233,19 @@
     * @param  {string} url 接口地址
     * @param  {string} name JSONP回调函数名称
     */
    jsonp: function(url, name='jsonp'){
    jsonp: function (url, name = 'jsonp') {
        return new Promise((resolve) => {
            var script = document.createElement('script')
            var _id = `jsonp${Math.ceil(Math.random() * 1000000)}`
            script.id = _id
            script.type = 'text/javascript'
            script.src = url
            window[name] =(response) => {
            window[name] = (response) => {
                resolve(response)
                document.getElementsByTagName('head')[0].removeChild(script)
                try {
                    delete window[name];
                }catch(e){
                } catch (e) {
                    window[name] = undefined;
                }
            }
src/views/tpm/MachineGroup.vue
@@ -1,7 +1,7 @@
<!--
 * @Date: 2024-04-27 20:02:44
 * @LastEditors: Sneed
 * @LastEditTime: 2024-04-27 20:49:52
 * @LastEditTime: 2024-04-27 21:40:33
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/tpm/MachineGroup.vue
-->
<template>
@@ -9,8 +9,9 @@
        <el-aside width="200px" v-loading="showGrouploading">
            <el-container>
                <el-main class="nopadding">
                    <el-tree ref="group" node-key="id" :data="group" :current-node-key="treeCheckKey"
                        :highlight-current="true" default-expand-all @node-click="groupClick"></el-tree>
                    <el-tree ref="group" node-key="id" :data="group" :current-node-key="form.id"
                        :highlight-current="true" :expand-on-click-node="false" default-expand-all
                        @node-click="groupClick"></el-tree>
                </el-main>
            </el-container>
        </el-aside>
@@ -24,13 +25,15 @@
            <el-main class="">
                <el-form :model="form" :rules="rules" ref="dialogForm" label-width="200px" label-position="left">
                    <el-form-item label="上级目录" prop="parentName">
                        <el-input style="width: 240px" v-model="form.parentName"></el-input>
                        <el-input disabled style="width: 240px" v-model="form.parentName"></el-input>
                    </el-form-item>
                    <el-form-item label="机器组名称" prop="name">
                        <el-input style="width: 240px" v-model="form.name" clearable></el-input>
                        <el-input :disabled="(form.id === '102' || form.id === '2')" style="width: 240px"
                            v-model="form.name" clearable></el-input>
                    </el-form-item>
                </el-form>
                <el-button @click="save" style="width: 100px" type="primary" plain>保存</el-button>
                <el-button @click="save" v-show="!(form.id === '102' || form.id === '2')" style="width: 100px"
                    type="primary" plain>保存</el-button>
            </el-main>
        </el-container>
    </el-container>
@@ -41,16 +44,16 @@
    data() {
        return {
            group: [],
            treeCheckKey: '',
            form: {
                code: '',
                name: '',
                id: '',
                groupType: '',
                groupCategory: '',
                parentName: '',
                parentId: '',
                id: '',
                groupType: 'group_machine',
                groupCategory: '1',
                code: ''
            },
            disabled: false,
        }
    },
    created() {
@@ -61,17 +64,62 @@
            this.$HTTP.get('/api/blade-cps/group/tree?groupCategory=1&groupType=group_machine').then(res => {
                if (res.code === 200) {
                    this.group = res.data
                    this.treeCheckKey = res.data[0].id
                    this.groupClick(res.data[0])
                }
            })
        },
        groupClick() {
        groupClick(node, node1) {
            console.log(node, node1?.parent?.data?.name)
            this.disabled = false
            Object.keys(this.form).forEach(item => {
                this.form[item] = node[item]
            })
            if (node1?.parent?.data?.name) {
                this.form.parentName = node1?.parent?.data?.name
            }
            if (node.id === '102' || node.id === '2') {
                this.form.parentName = node.name
                this.disabled = true
            }
        },
        addChild() {
            let { name, id, groupType, groupCategory } = this.form
            this.form.id = ''
            this.form.name = ''
            this.form.code = ''
            this.form.groupType = groupType
            this.form.groupCategory = groupCategory
            this.form.parentName = name
            this.form.parentId = id
        },
        del() {
            this.$confirm(
                '确认删除该机器组?',
                {
                    distinguishCancelAndClose: true,
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                }
            )
                .then(() => {
                    this.$HTTP.delete('/api/blade-cps/group/deleteGroup', {}, { params: { groupId: this.form.id } }).then(res => {
                        if (res.code === 200) {
                            this.$message.success("操作成功");
                            this.getTreeData()
                        }
                    })
                }).catch(() => {
                    this.$message.success("取消操作");
                })
        },
        addChild() { },
        del() { },
        save() {
            this.group = []
            this.$HTTP.post('/api/blade-cps/group', this.form).then(res => {
                if (res.code === 200) {
                    this.getTreeData()
                }
            })
        }
    }
}
src/views/tpm/machine-management.vue
@@ -51,19 +51,10 @@
            },
            immediate: true
        },
        treeCheckedNode: {
            handler(val) {
                this.addGroupShow = false
                Object.keys(this.form).forEach(key => {
                    this.form[key] = val?.[key]
                })
            },
            deep: true
        }
    },
    created() {
        this.init()
        this.queryList()
        // this.init()
        // this.queryList()
    },
    methods: {