mirror of
				https://github.com/veops/cmdb.git
				synced 2025-11-04 05:36:17 +08:00 
			
		
		
		
	feat:预定义值支持脚本&&密码存储&&一些bugfix (#239)
This commit is contained in:
		@@ -54,6 +54,48 @@
 | 
			
		||||
      <div class="content unicode" style="display: block;">
 | 
			
		||||
          <ul class="icon_lists dib-box">
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
              <span class="icon iconfont"></span>
 | 
			
		||||
                <div class="name">icon-xianxing-password</div>
 | 
			
		||||
                <div class="code-name">&#xe894;</div>
 | 
			
		||||
              </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
              <span class="icon iconfont"></span>
 | 
			
		||||
                <div class="name">icon-xianxing-link</div>
 | 
			
		||||
                <div class="code-name">&#xe895;</div>
 | 
			
		||||
              </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
              <span class="icon iconfont"></span>
 | 
			
		||||
                <div class="name">itsm-oneclick download</div>
 | 
			
		||||
                <div class="code-name">&#xe892;</div>
 | 
			
		||||
              </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
              <span class="icon iconfont"></span>
 | 
			
		||||
                <div class="name">itsm-package download</div>
 | 
			
		||||
                <div class="code-name">&#xe893;</div>
 | 
			
		||||
              </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
              <span class="icon iconfont"></span>
 | 
			
		||||
                <div class="name">weixin</div>
 | 
			
		||||
                <div class="code-name">&#xe891;</div>
 | 
			
		||||
              </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
              <span class="icon iconfont"></span>
 | 
			
		||||
                <div class="name">itsm-again</div>
 | 
			
		||||
                <div class="code-name">&#xe88f;</div>
 | 
			
		||||
              </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
              <span class="icon iconfont"></span>
 | 
			
		||||
                <div class="name">itsm-next</div>
 | 
			
		||||
                <div class="code-name">&#xe890;</div>
 | 
			
		||||
              </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
              <span class="icon iconfont"></span>
 | 
			
		||||
                <div class="name">wechatApp</div>
 | 
			
		||||
@@ -4002,9 +4044,9 @@
 | 
			
		||||
<pre><code class="language-css"
 | 
			
		||||
>@font-face {
 | 
			
		||||
  font-family: 'iconfont';
 | 
			
		||||
  src: url('iconfont.woff2?t=1696815443987') format('woff2'),
 | 
			
		||||
       url('iconfont.woff?t=1696815443987') format('woff'),
 | 
			
		||||
       url('iconfont.ttf?t=1696815443987') format('truetype');
 | 
			
		||||
  src: url('iconfont.woff2?t=1698273699449') format('woff2'),
 | 
			
		||||
       url('iconfont.woff?t=1698273699449') format('woff'),
 | 
			
		||||
       url('iconfont.ttf?t=1698273699449') format('truetype');
 | 
			
		||||
}
 | 
			
		||||
</code></pre>
 | 
			
		||||
          <h3 id="-iconfont-">第二步:定义使用 iconfont 的样式</h3>
 | 
			
		||||
@@ -4030,6 +4072,69 @@
 | 
			
		||||
      <div class="content font-class">
 | 
			
		||||
        <ul class="icon_lists dib-box">
 | 
			
		||||
          
 | 
			
		||||
          <li class="dib">
 | 
			
		||||
            <span class="icon iconfont icon-xianxing-password"></span>
 | 
			
		||||
            <div class="name">
 | 
			
		||||
              icon-xianxing-password
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="code-name">.icon-xianxing-password
 | 
			
		||||
            </div>
 | 
			
		||||
          </li>
 | 
			
		||||
          
 | 
			
		||||
          <li class="dib">
 | 
			
		||||
            <span class="icon iconfont icon-xianxing-link"></span>
 | 
			
		||||
            <div class="name">
 | 
			
		||||
              icon-xianxing-link
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="code-name">.icon-xianxing-link
 | 
			
		||||
            </div>
 | 
			
		||||
          </li>
 | 
			
		||||
          
 | 
			
		||||
          <li class="dib">
 | 
			
		||||
            <span class="icon iconfont a-itsm-oneclickdownload"></span>
 | 
			
		||||
            <div class="name">
 | 
			
		||||
              itsm-oneclick download
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="code-name">.a-itsm-oneclickdownload
 | 
			
		||||
            </div>
 | 
			
		||||
          </li>
 | 
			
		||||
          
 | 
			
		||||
          <li class="dib">
 | 
			
		||||
            <span class="icon iconfont a-itsm-packagedownload"></span>
 | 
			
		||||
            <div class="name">
 | 
			
		||||
              itsm-package download
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="code-name">.a-itsm-packagedownload
 | 
			
		||||
            </div>
 | 
			
		||||
          </li>
 | 
			
		||||
          
 | 
			
		||||
          <li class="dib">
 | 
			
		||||
            <span class="icon iconfont a-Frame4"></span>
 | 
			
		||||
            <div class="name">
 | 
			
		||||
              weixin
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="code-name">.a-Frame4
 | 
			
		||||
            </div>
 | 
			
		||||
          </li>
 | 
			
		||||
          
 | 
			
		||||
          <li class="dib">
 | 
			
		||||
            <span class="icon iconfont itsm-again"></span>
 | 
			
		||||
            <div class="name">
 | 
			
		||||
              itsm-again
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="code-name">.itsm-again
 | 
			
		||||
            </div>
 | 
			
		||||
          </li>
 | 
			
		||||
          
 | 
			
		||||
          <li class="dib">
 | 
			
		||||
            <span class="icon iconfont itsm-next"></span>
 | 
			
		||||
            <div class="name">
 | 
			
		||||
              itsm-next
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="code-name">.itsm-next
 | 
			
		||||
            </div>
 | 
			
		||||
          </li>
 | 
			
		||||
          
 | 
			
		||||
          <li class="dib">
 | 
			
		||||
            <span class="icon iconfont wechatApp"></span>
 | 
			
		||||
            <div class="name">
 | 
			
		||||
@@ -9952,6 +10057,62 @@
 | 
			
		||||
      <div class="content symbol">
 | 
			
		||||
          <ul class="icon_lists dib-box">
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
                <svg class="icon svg-icon" aria-hidden="true">
 | 
			
		||||
                  <use xlink:href="#icon-xianxing-password"></use>
 | 
			
		||||
                </svg>
 | 
			
		||||
                <div class="name">icon-xianxing-password</div>
 | 
			
		||||
                <div class="code-name">#icon-xianxing-password</div>
 | 
			
		||||
            </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
                <svg class="icon svg-icon" aria-hidden="true">
 | 
			
		||||
                  <use xlink:href="#icon-xianxing-link"></use>
 | 
			
		||||
                </svg>
 | 
			
		||||
                <div class="name">icon-xianxing-link</div>
 | 
			
		||||
                <div class="code-name">#icon-xianxing-link</div>
 | 
			
		||||
            </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
                <svg class="icon svg-icon" aria-hidden="true">
 | 
			
		||||
                  <use xlink:href="#a-itsm-oneclickdownload"></use>
 | 
			
		||||
                </svg>
 | 
			
		||||
                <div class="name">itsm-oneclick download</div>
 | 
			
		||||
                <div class="code-name">#a-itsm-oneclickdownload</div>
 | 
			
		||||
            </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
                <svg class="icon svg-icon" aria-hidden="true">
 | 
			
		||||
                  <use xlink:href="#a-itsm-packagedownload"></use>
 | 
			
		||||
                </svg>
 | 
			
		||||
                <div class="name">itsm-package download</div>
 | 
			
		||||
                <div class="code-name">#a-itsm-packagedownload</div>
 | 
			
		||||
            </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
                <svg class="icon svg-icon" aria-hidden="true">
 | 
			
		||||
                  <use xlink:href="#a-Frame4"></use>
 | 
			
		||||
                </svg>
 | 
			
		||||
                <div class="name">weixin</div>
 | 
			
		||||
                <div class="code-name">#a-Frame4</div>
 | 
			
		||||
            </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
                <svg class="icon svg-icon" aria-hidden="true">
 | 
			
		||||
                  <use xlink:href="#itsm-again"></use>
 | 
			
		||||
                </svg>
 | 
			
		||||
                <div class="name">itsm-again</div>
 | 
			
		||||
                <div class="code-name">#itsm-again</div>
 | 
			
		||||
            </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
                <svg class="icon svg-icon" aria-hidden="true">
 | 
			
		||||
                  <use xlink:href="#itsm-next"></use>
 | 
			
		||||
                </svg>
 | 
			
		||||
                <div class="name">itsm-next</div>
 | 
			
		||||
                <div class="code-name">#itsm-next</div>
 | 
			
		||||
            </li>
 | 
			
		||||
          
 | 
			
		||||
            <li class="dib">
 | 
			
		||||
                <svg class="icon svg-icon" aria-hidden="true">
 | 
			
		||||
                  <use xlink:href="#wechatApp"></use>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
@font-face {
 | 
			
		||||
  font-family: "iconfont"; /* Project id 3857903 */
 | 
			
		||||
  src: url('iconfont.woff2?t=1696815443987') format('woff2'),
 | 
			
		||||
       url('iconfont.woff?t=1696815443987') format('woff'),
 | 
			
		||||
       url('iconfont.ttf?t=1696815443987') format('truetype');
 | 
			
		||||
  src: url('iconfont.woff2?t=1698273699449') format('woff2'),
 | 
			
		||||
       url('iconfont.woff?t=1698273699449') format('woff'),
 | 
			
		||||
       url('iconfont.ttf?t=1698273699449') format('truetype');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.iconfont {
 | 
			
		||||
@@ -13,6 +13,34 @@
 | 
			
		||||
  -moz-osx-font-smoothing: grayscale;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.icon-xianxing-password:before {
 | 
			
		||||
  content: "\e894";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.icon-xianxing-link:before {
 | 
			
		||||
  content: "\e895";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.a-itsm-oneclickdownload:before {
 | 
			
		||||
  content: "\e892";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.a-itsm-packagedownload:before {
 | 
			
		||||
  content: "\e893";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.a-Frame4:before {
 | 
			
		||||
  content: "\e891";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.itsm-again:before {
 | 
			
		||||
  content: "\e88f";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.itsm-next:before {
 | 
			
		||||
  content: "\e890";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.wechatApp:before {
 | 
			
		||||
  content: "\e88e";
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -5,6 +5,55 @@
 | 
			
		||||
  "css_prefix_text": "",
 | 
			
		||||
  "description": "",
 | 
			
		||||
  "glyphs": [
 | 
			
		||||
    {
 | 
			
		||||
      "icon_id": "37830610",
 | 
			
		||||
      "name": "icon-xianxing-password",
 | 
			
		||||
      "font_class": "icon-xianxing-password",
 | 
			
		||||
      "unicode": "e894",
 | 
			
		||||
      "unicode_decimal": 59540
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "icon_id": "37830609",
 | 
			
		||||
      "name": "icon-xianxing-link",
 | 
			
		||||
      "font_class": "icon-xianxing-link",
 | 
			
		||||
      "unicode": "e895",
 | 
			
		||||
      "unicode_decimal": 59541
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "icon_id": "37822199",
 | 
			
		||||
      "name": "itsm-oneclick download",
 | 
			
		||||
      "font_class": "a-itsm-oneclickdownload",
 | 
			
		||||
      "unicode": "e892",
 | 
			
		||||
      "unicode_decimal": 59538
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "icon_id": "37822198",
 | 
			
		||||
      "name": "itsm-package download",
 | 
			
		||||
      "font_class": "a-itsm-packagedownload",
 | 
			
		||||
      "unicode": "e893",
 | 
			
		||||
      "unicode_decimal": 59539
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "icon_id": "37772067",
 | 
			
		||||
      "name": "weixin",
 | 
			
		||||
      "font_class": "a-Frame4",
 | 
			
		||||
      "unicode": "e891",
 | 
			
		||||
      "unicode_decimal": 59537
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "icon_id": "37632784",
 | 
			
		||||
      "name": "itsm-again",
 | 
			
		||||
      "font_class": "itsm-again",
 | 
			
		||||
      "unicode": "e88f",
 | 
			
		||||
      "unicode_decimal": 59535
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "icon_id": "37632783",
 | 
			
		||||
      "name": "itsm-next",
 | 
			
		||||
      "font_class": "itsm-next",
 | 
			
		||||
      "unicode": "e890",
 | 
			
		||||
      "unicode_decimal": 59536
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "icon_id": "37590786",
 | 
			
		||||
      "name": "wechatApp",
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -1,282 +1,290 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div>
 | 
			
		||||
    <a-popover
 | 
			
		||||
      v-if="isDropdown"
 | 
			
		||||
      v-model="visible"
 | 
			
		||||
      trigger="click"
 | 
			
		||||
      :placement="placement"
 | 
			
		||||
      overlayClassName="table-filter"
 | 
			
		||||
      @visibleChange="visibleChange"
 | 
			
		||||
    >
 | 
			
		||||
      <slot name="popover_item">
 | 
			
		||||
        <a-button type="primary" ghost>条件过滤<a-icon type="filter"/></a-button>
 | 
			
		||||
      </slot>
 | 
			
		||||
      <template slot="content">
 | 
			
		||||
        <Expression v-model="ruleList" :canSearchPreferenceAttrList="canSearchPreferenceAttrList" />
 | 
			
		||||
        <a-divider :style="{ margin: '10px 0' }" />
 | 
			
		||||
        <div style="width:534px">
 | 
			
		||||
          <a-space :style="{ display: 'flex', justifyContent: 'flex-end' }">
 | 
			
		||||
            <a-button type="primary" size="small" @click="handleSubmit">确定</a-button>
 | 
			
		||||
            <a-button size="small" @click="handleClear">清空</a-button>
 | 
			
		||||
          </a-space>
 | 
			
		||||
        </div>
 | 
			
		||||
      </template>
 | 
			
		||||
    </a-popover>
 | 
			
		||||
    <Expression v-else v-model="ruleList" :canSearchPreferenceAttrList="canSearchPreferenceAttrList" />
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { v4 as uuidv4 } from 'uuid'
 | 
			
		||||
import Expression from './expression.vue'
 | 
			
		||||
import { advancedExpList, compareTypeList } from './constants'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'FilterComp',
 | 
			
		||||
  components: { Expression },
 | 
			
		||||
  props: {
 | 
			
		||||
    canSearchPreferenceAttrList: {
 | 
			
		||||
      type: Array,
 | 
			
		||||
      required: true,
 | 
			
		||||
      default: () => [],
 | 
			
		||||
    },
 | 
			
		||||
    expression: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: '',
 | 
			
		||||
    },
 | 
			
		||||
    regQ: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: '(?<=q=).+(?=&)|(?<=q=).+$',
 | 
			
		||||
    },
 | 
			
		||||
    placement: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: 'bottomRight',
 | 
			
		||||
    },
 | 
			
		||||
    isDropdown: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: true,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      advancedExpList,
 | 
			
		||||
      compareTypeList,
 | 
			
		||||
      visible: false,
 | 
			
		||||
      ruleList: [],
 | 
			
		||||
      filterExp: '',
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  methods: {
 | 
			
		||||
    visibleChange(open, isInitOne = true) {
 | 
			
		||||
      // isInitOne  初始化exp为空时,ruleList是否默认给一条
 | 
			
		||||
      //   const regQ = /(?<=q=).+(?=&)|(?<=q=).+$/g
 | 
			
		||||
      const exp = this.expression.match(new RegExp(this.regQ, 'g'))
 | 
			
		||||
        ? this.expression.match(new RegExp(this.regQ, 'g'))[0]
 | 
			
		||||
        : null
 | 
			
		||||
      if (open && exp) {
 | 
			
		||||
        const expArray = exp.split(',').map((item) => {
 | 
			
		||||
          let has_not = ''
 | 
			
		||||
          const key = item.split(':')[0]
 | 
			
		||||
          const val = item
 | 
			
		||||
            .split(':')
 | 
			
		||||
            .slice(1)
 | 
			
		||||
            .join(':')
 | 
			
		||||
          let type, property, exp, value, min, max, compareType
 | 
			
		||||
          if (key.includes('-')) {
 | 
			
		||||
            type = 'or'
 | 
			
		||||
            if (key.includes('~')) {
 | 
			
		||||
              property = key.substring(2)
 | 
			
		||||
              has_not = '~'
 | 
			
		||||
            } else {
 | 
			
		||||
              property = key.substring(1)
 | 
			
		||||
            }
 | 
			
		||||
          } else {
 | 
			
		||||
            type = 'and'
 | 
			
		||||
            if (key.includes('~')) {
 | 
			
		||||
              property = key.substring(1)
 | 
			
		||||
              has_not = '~'
 | 
			
		||||
            } else {
 | 
			
		||||
              property = key
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          const in_reg = /(?<=\().+(?=\))/g
 | 
			
		||||
          const range_reg = /(?<=\[).+(?=\])/g
 | 
			
		||||
          const compare_reg = /(?<=>=|<=|>(?!=)|<(?!=)).+/
 | 
			
		||||
          if (val === '*') {
 | 
			
		||||
            exp = has_not + 'value'
 | 
			
		||||
            value = ''
 | 
			
		||||
          } else if (in_reg.test(val)) {
 | 
			
		||||
            exp = has_not + 'in'
 | 
			
		||||
            value = val.match(in_reg)[0]
 | 
			
		||||
          } else if (range_reg.test(val)) {
 | 
			
		||||
            exp = has_not + 'range'
 | 
			
		||||
            value = val.match(range_reg)[0]
 | 
			
		||||
            min = value.split('_TO_')[0]
 | 
			
		||||
            max = value.split('_TO_')[1]
 | 
			
		||||
          } else if (compare_reg.test(val)) {
 | 
			
		||||
            exp = has_not + 'compare'
 | 
			
		||||
            value = val.match(compare_reg)[0]
 | 
			
		||||
            const _compareType = val.substring(0, val.match(compare_reg)['index'])
 | 
			
		||||
            const idx = compareTypeList.findIndex((item) => item.label === _compareType)
 | 
			
		||||
            compareType = compareTypeList[idx].value
 | 
			
		||||
          } else if (!val.includes('*')) {
 | 
			
		||||
            exp = has_not + 'is'
 | 
			
		||||
            value = val
 | 
			
		||||
          } else {
 | 
			
		||||
            const resList = [
 | 
			
		||||
              ['contain', /(?<=\*).*(?=\*)/g],
 | 
			
		||||
              ['end_with', /(?<=\*).+/g],
 | 
			
		||||
              ['start_with', /.+(?=\*)/g],
 | 
			
		||||
            ]
 | 
			
		||||
            for (let i = 0; i < 3; i++) {
 | 
			
		||||
              const reg = resList[i]
 | 
			
		||||
              if (reg[1].test(val)) {
 | 
			
		||||
                exp = has_not + reg[0]
 | 
			
		||||
                value = val.match(reg[1])[0]
 | 
			
		||||
                break
 | 
			
		||||
              }
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          return {
 | 
			
		||||
            id: uuidv4(),
 | 
			
		||||
            type,
 | 
			
		||||
            property,
 | 
			
		||||
            exp,
 | 
			
		||||
            value,
 | 
			
		||||
            min,
 | 
			
		||||
            max,
 | 
			
		||||
            compareType,
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
        this.ruleList = [...expArray]
 | 
			
		||||
      } else if (open) {
 | 
			
		||||
        this.ruleList = isInitOne
 | 
			
		||||
          ? [
 | 
			
		||||
              {
 | 
			
		||||
                id: uuidv4(),
 | 
			
		||||
                type: 'and',
 | 
			
		||||
                property:
 | 
			
		||||
                  this.canSearchPreferenceAttrList && this.canSearchPreferenceAttrList.length
 | 
			
		||||
                    ? this.canSearchPreferenceAttrList[0].name
 | 
			
		||||
                    : undefined,
 | 
			
		||||
                exp: 'is',
 | 
			
		||||
                value: null,
 | 
			
		||||
              },
 | 
			
		||||
            ]
 | 
			
		||||
          : []
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleClear() {
 | 
			
		||||
      this.ruleList = [
 | 
			
		||||
        {
 | 
			
		||||
          id: uuidv4(),
 | 
			
		||||
          type: 'and',
 | 
			
		||||
          property: this.canSearchPreferenceAttrList[0].name,
 | 
			
		||||
          exp: 'is',
 | 
			
		||||
          value: null,
 | 
			
		||||
        },
 | 
			
		||||
      ]
 | 
			
		||||
      this.filterExp = ''
 | 
			
		||||
      this.visible = false
 | 
			
		||||
      this.$emit('setExpFromFilter', this.filterExp)
 | 
			
		||||
    },
 | 
			
		||||
    handleSubmit() {
 | 
			
		||||
      if (this.ruleList && this.ruleList.length) {
 | 
			
		||||
        this.ruleList[0].type = 'and' // 增删后,以防万一第一个不是and
 | 
			
		||||
        this.filterExp = ''
 | 
			
		||||
        const expList = this.ruleList.map((rule) => {
 | 
			
		||||
          let singleRuleExp = ''
 | 
			
		||||
          let _exp = rule.exp
 | 
			
		||||
          if (rule.type === 'or') {
 | 
			
		||||
            singleRuleExp += '-'
 | 
			
		||||
          }
 | 
			
		||||
          if (rule.exp.includes('~')) {
 | 
			
		||||
            singleRuleExp += '~'
 | 
			
		||||
            _exp = rule.exp.split('~')[1]
 | 
			
		||||
          }
 | 
			
		||||
          singleRuleExp += `${rule.property}:`
 | 
			
		||||
          if (_exp === 'is') {
 | 
			
		||||
            singleRuleExp += `${rule.value ?? ''}`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'contain') {
 | 
			
		||||
            singleRuleExp += `*${rule.value ?? ''}*`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'start_with') {
 | 
			
		||||
            singleRuleExp += `${rule.value ?? ''}*`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'end_with') {
 | 
			
		||||
            singleRuleExp += `*${rule.value ?? ''}`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'value') {
 | 
			
		||||
            singleRuleExp += `*`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'in') {
 | 
			
		||||
            singleRuleExp += `(${rule.value ?? ''})`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'range') {
 | 
			
		||||
            singleRuleExp += `[${rule.min}_TO_${rule.max}]`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'compare') {
 | 
			
		||||
            const idx = compareTypeList.findIndex((item) => item.value === rule.compareType)
 | 
			
		||||
            singleRuleExp += `${compareTypeList[idx].label}${rule.value ?? ''}`
 | 
			
		||||
          }
 | 
			
		||||
          return singleRuleExp
 | 
			
		||||
        })
 | 
			
		||||
        this.filterExp = expList.join(',')
 | 
			
		||||
        this.$emit('setExpFromFilter', this.filterExp)
 | 
			
		||||
      } else {
 | 
			
		||||
        this.$emit('setExpFromFilter', '')
 | 
			
		||||
      }
 | 
			
		||||
      this.visible = false
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="less" scoped>
 | 
			
		||||
.table-filter {
 | 
			
		||||
  .table-filter-add {
 | 
			
		||||
    margin-top: 10px;
 | 
			
		||||
    & > a {
 | 
			
		||||
      padding: 2px 8px;
 | 
			
		||||
      &:hover {
 | 
			
		||||
        background-color: #f0faff;
 | 
			
		||||
        border-radius: 5px;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  .table-filter-extra-icon {
 | 
			
		||||
    padding: 0px 2px;
 | 
			
		||||
    &:hover {
 | 
			
		||||
      display: inline-block;
 | 
			
		||||
      border-radius: 5px;
 | 
			
		||||
      background-color: #f0faff;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
 | 
			
		||||
<style lang="less">
 | 
			
		||||
.table-filter-extra-operation {
 | 
			
		||||
  .ant-popover-inner-content {
 | 
			
		||||
    padding: 3px 4px;
 | 
			
		||||
    .operation {
 | 
			
		||||
      cursor: pointer;
 | 
			
		||||
      width: 90px;
 | 
			
		||||
      height: 30px;
 | 
			
		||||
      line-height: 30px;
 | 
			
		||||
      padding: 3px 4px;
 | 
			
		||||
      border-radius: 5px;
 | 
			
		||||
      transition: all 0.3s;
 | 
			
		||||
      &:hover {
 | 
			
		||||
        background-color: #f0faff;
 | 
			
		||||
      }
 | 
			
		||||
      > .anticon {
 | 
			
		||||
        margin-right: 10px;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
<template>
 | 
			
		||||
  <div>
 | 
			
		||||
    <a-popover
 | 
			
		||||
      v-if="isDropdown"
 | 
			
		||||
      v-model="visible"
 | 
			
		||||
      trigger="click"
 | 
			
		||||
      :placement="placement"
 | 
			
		||||
      overlayClassName="table-filter"
 | 
			
		||||
      @visibleChange="visibleChange"
 | 
			
		||||
    >
 | 
			
		||||
      <slot name="popover_item">
 | 
			
		||||
        <a-button type="primary" ghost>条件过滤<a-icon type="filter"/></a-button>
 | 
			
		||||
      </slot>
 | 
			
		||||
      <template slot="content">
 | 
			
		||||
        <Expression
 | 
			
		||||
          v-model="ruleList"
 | 
			
		||||
          :canSearchPreferenceAttrList="canSearchPreferenceAttrList.filter((attr) => !attr.is_password)"
 | 
			
		||||
        />
 | 
			
		||||
        <a-divider :style="{ margin: '10px 0' }" />
 | 
			
		||||
        <div style="width:534px">
 | 
			
		||||
          <a-space :style="{ display: 'flex', justifyContent: 'flex-end' }">
 | 
			
		||||
            <a-button type="primary" size="small" @click="handleSubmit">确定</a-button>
 | 
			
		||||
            <a-button size="small" @click="handleClear">清空</a-button>
 | 
			
		||||
          </a-space>
 | 
			
		||||
        </div>
 | 
			
		||||
      </template>
 | 
			
		||||
    </a-popover>
 | 
			
		||||
    <Expression
 | 
			
		||||
      v-else
 | 
			
		||||
      v-model="ruleList"
 | 
			
		||||
      :canSearchPreferenceAttrList="canSearchPreferenceAttrList.filter((attr) => !attr.is_password)"
 | 
			
		||||
    />
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { v4 as uuidv4 } from 'uuid'
 | 
			
		||||
import Expression from './expression.vue'
 | 
			
		||||
import { advancedExpList, compareTypeList } from './constants'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'FilterComp',
 | 
			
		||||
  components: { Expression },
 | 
			
		||||
  props: {
 | 
			
		||||
    canSearchPreferenceAttrList: {
 | 
			
		||||
      type: Array,
 | 
			
		||||
      required: true,
 | 
			
		||||
      default: () => [],
 | 
			
		||||
    },
 | 
			
		||||
    expression: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: '',
 | 
			
		||||
    },
 | 
			
		||||
    regQ: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: '(?<=q=).+(?=&)|(?<=q=).+$',
 | 
			
		||||
    },
 | 
			
		||||
    placement: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: 'bottomRight',
 | 
			
		||||
    },
 | 
			
		||||
    isDropdown: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: true,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      advancedExpList,
 | 
			
		||||
      compareTypeList,
 | 
			
		||||
      visible: false,
 | 
			
		||||
      ruleList: [],
 | 
			
		||||
      filterExp: '',
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  methods: {
 | 
			
		||||
    visibleChange(open, isInitOne = true) {
 | 
			
		||||
      // isInitOne  初始化exp为空时,ruleList是否默认给一条
 | 
			
		||||
      //   const regQ = /(?<=q=).+(?=&)|(?<=q=).+$/g
 | 
			
		||||
      const exp = this.expression.match(new RegExp(this.regQ, 'g'))
 | 
			
		||||
        ? this.expression.match(new RegExp(this.regQ, 'g'))[0]
 | 
			
		||||
        : null
 | 
			
		||||
      if (open && exp) {
 | 
			
		||||
        const expArray = exp.split(',').map((item) => {
 | 
			
		||||
          let has_not = ''
 | 
			
		||||
          const key = item.split(':')[0]
 | 
			
		||||
          const val = item
 | 
			
		||||
            .split(':')
 | 
			
		||||
            .slice(1)
 | 
			
		||||
            .join(':')
 | 
			
		||||
          let type, property, exp, value, min, max, compareType
 | 
			
		||||
          if (key.includes('-')) {
 | 
			
		||||
            type = 'or'
 | 
			
		||||
            if (key.includes('~')) {
 | 
			
		||||
              property = key.substring(2)
 | 
			
		||||
              has_not = '~'
 | 
			
		||||
            } else {
 | 
			
		||||
              property = key.substring(1)
 | 
			
		||||
            }
 | 
			
		||||
          } else {
 | 
			
		||||
            type = 'and'
 | 
			
		||||
            if (key.includes('~')) {
 | 
			
		||||
              property = key.substring(1)
 | 
			
		||||
              has_not = '~'
 | 
			
		||||
            } else {
 | 
			
		||||
              property = key
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          const in_reg = /(?<=\().+(?=\))/g
 | 
			
		||||
          const range_reg = /(?<=\[).+(?=\])/g
 | 
			
		||||
          const compare_reg = /(?<=>=|<=|>(?!=)|<(?!=)).+/
 | 
			
		||||
          if (val === '*') {
 | 
			
		||||
            exp = has_not + 'value'
 | 
			
		||||
            value = ''
 | 
			
		||||
          } else if (in_reg.test(val)) {
 | 
			
		||||
            exp = has_not + 'in'
 | 
			
		||||
            value = val.match(in_reg)[0]
 | 
			
		||||
          } else if (range_reg.test(val)) {
 | 
			
		||||
            exp = has_not + 'range'
 | 
			
		||||
            value = val.match(range_reg)[0]
 | 
			
		||||
            min = value.split('_TO_')[0]
 | 
			
		||||
            max = value.split('_TO_')[1]
 | 
			
		||||
          } else if (compare_reg.test(val)) {
 | 
			
		||||
            exp = has_not + 'compare'
 | 
			
		||||
            value = val.match(compare_reg)[0]
 | 
			
		||||
            const _compareType = val.substring(0, val.match(compare_reg)['index'])
 | 
			
		||||
            const idx = compareTypeList.findIndex((item) => item.label === _compareType)
 | 
			
		||||
            compareType = compareTypeList[idx].value
 | 
			
		||||
          } else if (!val.includes('*')) {
 | 
			
		||||
            exp = has_not + 'is'
 | 
			
		||||
            value = val
 | 
			
		||||
          } else {
 | 
			
		||||
            const resList = [
 | 
			
		||||
              ['contain', /(?<=\*).*(?=\*)/g],
 | 
			
		||||
              ['end_with', /(?<=\*).+/g],
 | 
			
		||||
              ['start_with', /.+(?=\*)/g],
 | 
			
		||||
            ]
 | 
			
		||||
            for (let i = 0; i < 3; i++) {
 | 
			
		||||
              const reg = resList[i]
 | 
			
		||||
              if (reg[1].test(val)) {
 | 
			
		||||
                exp = has_not + reg[0]
 | 
			
		||||
                value = val.match(reg[1])[0]
 | 
			
		||||
                break
 | 
			
		||||
              }
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          return {
 | 
			
		||||
            id: uuidv4(),
 | 
			
		||||
            type,
 | 
			
		||||
            property,
 | 
			
		||||
            exp,
 | 
			
		||||
            value,
 | 
			
		||||
            min,
 | 
			
		||||
            max,
 | 
			
		||||
            compareType,
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
        this.ruleList = [...expArray]
 | 
			
		||||
      } else if (open) {
 | 
			
		||||
        const _canSearchPreferenceAttrList = this.canSearchPreferenceAttrList.filter((attr) => !attr.is_password)
 | 
			
		||||
        this.ruleList = isInitOne
 | 
			
		||||
          ? [
 | 
			
		||||
              {
 | 
			
		||||
                id: uuidv4(),
 | 
			
		||||
                type: 'and',
 | 
			
		||||
                property:
 | 
			
		||||
                  _canSearchPreferenceAttrList && _canSearchPreferenceAttrList.length
 | 
			
		||||
                    ? _canSearchPreferenceAttrList[0].name
 | 
			
		||||
                    : undefined,
 | 
			
		||||
                exp: 'is',
 | 
			
		||||
                value: null,
 | 
			
		||||
              },
 | 
			
		||||
            ]
 | 
			
		||||
          : []
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleClear() {
 | 
			
		||||
      this.ruleList = [
 | 
			
		||||
        {
 | 
			
		||||
          id: uuidv4(),
 | 
			
		||||
          type: 'and',
 | 
			
		||||
          property: this.canSearchPreferenceAttrList[0].name,
 | 
			
		||||
          exp: 'is',
 | 
			
		||||
          value: null,
 | 
			
		||||
        },
 | 
			
		||||
      ]
 | 
			
		||||
      this.filterExp = ''
 | 
			
		||||
      this.visible = false
 | 
			
		||||
      this.$emit('setExpFromFilter', this.filterExp)
 | 
			
		||||
    },
 | 
			
		||||
    handleSubmit() {
 | 
			
		||||
      if (this.ruleList && this.ruleList.length) {
 | 
			
		||||
        this.ruleList[0].type = 'and' // 增删后,以防万一第一个不是and
 | 
			
		||||
        this.filterExp = ''
 | 
			
		||||
        const expList = this.ruleList.map((rule) => {
 | 
			
		||||
          let singleRuleExp = ''
 | 
			
		||||
          let _exp = rule.exp
 | 
			
		||||
          if (rule.type === 'or') {
 | 
			
		||||
            singleRuleExp += '-'
 | 
			
		||||
          }
 | 
			
		||||
          if (rule.exp.includes('~')) {
 | 
			
		||||
            singleRuleExp += '~'
 | 
			
		||||
            _exp = rule.exp.split('~')[1]
 | 
			
		||||
          }
 | 
			
		||||
          singleRuleExp += `${rule.property}:`
 | 
			
		||||
          if (_exp === 'is') {
 | 
			
		||||
            singleRuleExp += `${rule.value ?? ''}`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'contain') {
 | 
			
		||||
            singleRuleExp += `*${rule.value ?? ''}*`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'start_with') {
 | 
			
		||||
            singleRuleExp += `${rule.value ?? ''}*`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'end_with') {
 | 
			
		||||
            singleRuleExp += `*${rule.value ?? ''}`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'value') {
 | 
			
		||||
            singleRuleExp += `*`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'in') {
 | 
			
		||||
            singleRuleExp += `(${rule.value ?? ''})`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'range') {
 | 
			
		||||
            singleRuleExp += `[${rule.min}_TO_${rule.max}]`
 | 
			
		||||
          }
 | 
			
		||||
          if (_exp === 'compare') {
 | 
			
		||||
            const idx = compareTypeList.findIndex((item) => item.value === rule.compareType)
 | 
			
		||||
            singleRuleExp += `${compareTypeList[idx].label}${rule.value ?? ''}`
 | 
			
		||||
          }
 | 
			
		||||
          return singleRuleExp
 | 
			
		||||
        })
 | 
			
		||||
        this.filterExp = expList.join(',')
 | 
			
		||||
        this.$emit('setExpFromFilter', this.filterExp)
 | 
			
		||||
      } else {
 | 
			
		||||
        this.$emit('setExpFromFilter', '')
 | 
			
		||||
      }
 | 
			
		||||
      this.visible = false
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="less" scoped>
 | 
			
		||||
.table-filter {
 | 
			
		||||
  .table-filter-add {
 | 
			
		||||
    margin-top: 10px;
 | 
			
		||||
    & > a {
 | 
			
		||||
      padding: 2px 8px;
 | 
			
		||||
      &:hover {
 | 
			
		||||
        background-color: #f0faff;
 | 
			
		||||
        border-radius: 5px;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  .table-filter-extra-icon {
 | 
			
		||||
    padding: 0px 2px;
 | 
			
		||||
    &:hover {
 | 
			
		||||
      display: inline-block;
 | 
			
		||||
      border-radius: 5px;
 | 
			
		||||
      background-color: #f0faff;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
 | 
			
		||||
<style lang="less">
 | 
			
		||||
.table-filter-extra-operation {
 | 
			
		||||
  .ant-popover-inner-content {
 | 
			
		||||
    padding: 3px 4px;
 | 
			
		||||
    .operation {
 | 
			
		||||
      cursor: pointer;
 | 
			
		||||
      width: 90px;
 | 
			
		||||
      height: 30px;
 | 
			
		||||
      line-height: 30px;
 | 
			
		||||
      padding: 3px 4px;
 | 
			
		||||
      border-radius: 5px;
 | 
			
		||||
      transition: all 0.3s;
 | 
			
		||||
      &:hover {
 | 
			
		||||
        background-color: #f0faff;
 | 
			
		||||
      }
 | 
			
		||||
      > .anticon {
 | 
			
		||||
        margin-right: 10px;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,57 +1,45 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <span>
 | 
			
		||||
    <ops-icon :type="getPropertyIcon(attr)" />
 | 
			
		||||
  </span>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'ValueTypeIcon',
 | 
			
		||||
  props: {
 | 
			
		||||
    attr: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    getPropertyStyle(attr) {
 | 
			
		||||
      switch (attr.value_type) {
 | 
			
		||||
        case '0':
 | 
			
		||||
          return { color: '#cf1322', backgroundColor: '#fff1f0' }
 | 
			
		||||
        case '1':
 | 
			
		||||
          return { color: '#d4b106', backgroundColor: '#feffe6' }
 | 
			
		||||
        case '2':
 | 
			
		||||
          return { color: '#d46b08', backgroundColor: '#fff7e6' }
 | 
			
		||||
        case '3':
 | 
			
		||||
          return { color: '#531dab', backgroundColor: '#f9f0ff' }
 | 
			
		||||
        case '4':
 | 
			
		||||
          return { color: '#389e0d', backgroundColor: '#f6ffed' }
 | 
			
		||||
        case '5':
 | 
			
		||||
          return { color: '#08979c', backgroundColor: '#e6fffb' }
 | 
			
		||||
        case '6':
 | 
			
		||||
          return { color: '#c41d7f', backgroundColor: '#fff0f6' }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    getPropertyIcon(attr) {
 | 
			
		||||
      switch (attr.value_type) {
 | 
			
		||||
        case '0':
 | 
			
		||||
          return 'icon-xianxing-shishu'
 | 
			
		||||
        case '1':
 | 
			
		||||
          return 'icon-xianxing-fudianshu'
 | 
			
		||||
        case '2':
 | 
			
		||||
          return 'icon-xianxing-wenben'
 | 
			
		||||
        case '3':
 | 
			
		||||
          return 'icon-xianxing-datetime'
 | 
			
		||||
        case '4':
 | 
			
		||||
          return 'icon-xianxing-date'
 | 
			
		||||
        case '5':
 | 
			
		||||
          return 'icon-xianxing-time'
 | 
			
		||||
        case '6':
 | 
			
		||||
          return 'icon-xianxing-json'
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
<template>
 | 
			
		||||
  <span>
 | 
			
		||||
    <ops-icon :type="getPropertyIcon(attr)" />
 | 
			
		||||
  </span>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'ValueTypeIcon',
 | 
			
		||||
  props: {
 | 
			
		||||
    attr: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    getPropertyIcon(attr) {
 | 
			
		||||
      switch (attr.value_type) {
 | 
			
		||||
        case '0':
 | 
			
		||||
          return 'icon-xianxing-shishu'
 | 
			
		||||
        case '1':
 | 
			
		||||
          return 'icon-xianxing-fudianshu'
 | 
			
		||||
        case '2':
 | 
			
		||||
          if (attr.is_password) {
 | 
			
		||||
            return 'icon-xianxing-password'
 | 
			
		||||
          }
 | 
			
		||||
          if (attr.is_link) {
 | 
			
		||||
            return 'icon-xianxing-link'
 | 
			
		||||
          }
 | 
			
		||||
          return 'icon-xianxing-wenben'
 | 
			
		||||
        case '3':
 | 
			
		||||
          return 'icon-xianxing-datetime'
 | 
			
		||||
        case '4':
 | 
			
		||||
          return 'icon-xianxing-date'
 | 
			
		||||
        case '5':
 | 
			
		||||
          return 'icon-xianxing-time'
 | 
			
		||||
        case '6':
 | 
			
		||||
          return 'icon-xianxing-json'
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,170 +1,177 @@
 | 
			
		||||
import { axios } from '@/utils/request'
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 获取 ci_type 的属性
 | 
			
		||||
 * @param CITypeName
 | 
			
		||||
 * @param parameter
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function getCITypeAttributesByName(CITypeName, parameter) {
 | 
			
		||||
  return axios({
 | 
			
		||||
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeName}/attributes`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: parameter
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 获取 ci_type 的属性
 | 
			
		||||
 * @param CITypeId
 | 
			
		||||
 * @param parameter
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function getCITypeAttributesById(CITypeId, parameter) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: parameter
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 更新属性
 | 
			
		||||
 * @param attrId
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function updateAttributeById(attrId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes/${attrId}`,
 | 
			
		||||
    method: 'put',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 添加属性
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function createAttribute(data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes`,
 | 
			
		||||
    method: 'post',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 搜索属性/ 获取所有的属性
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function searchAttributes(params) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes/s`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: params
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getCITypeAttributesByTypeIds(params) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/attributes`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: params
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getCITypeCommonAttributesByTypeIds(params) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/common_attributes`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: params
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 删除属性
 | 
			
		||||
 * @param attrId
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function deleteAttributesById(attrId) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes/${attrId}`,
 | 
			
		||||
    method: 'delete'
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 绑定ci_type 属性
 | 
			
		||||
 * @param CITypeId
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function createCITypeAttributes(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes`,
 | 
			
		||||
    method: 'post',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 更新ci_type 属性
 | 
			
		||||
 * @param CITypeId
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function updateCITypeAttributesById(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes`,
 | 
			
		||||
    method: 'put',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 删除ci_type 属性
 | 
			
		||||
 * @param CITypeId
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function deleteCITypeAttributesById(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes`,
 | 
			
		||||
    method: 'delete',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function transferCITypeAttrIndex(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes/transfer`,
 | 
			
		||||
    method: 'POST',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function transferCITypeGroupIndex(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attribute_groups/transfer`,
 | 
			
		||||
    method: 'POST',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function canDefineComputed() {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/can_define_computed`,
 | 
			
		||||
    method: 'HEAD',
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function calcComputedAttribute(attr_id) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes/${attr_id}/calc_computed_attribute`,
 | 
			
		||||
    method: 'PUT',
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
import { axios } from '@/utils/request'
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 获取 ci_type 的属性
 | 
			
		||||
 * @param CITypeName
 | 
			
		||||
 * @param parameter
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function getCITypeAttributesByName(CITypeName, parameter) {
 | 
			
		||||
  return axios({
 | 
			
		||||
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeName}/attributes`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: parameter
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 获取 ci_type 的属性
 | 
			
		||||
 * @param CITypeId
 | 
			
		||||
 * @param parameter
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function getCITypeAttributesById(CITypeId, parameter) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: parameter
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 更新属性
 | 
			
		||||
 * @param attrId
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function updateAttributeById(attrId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes/${attrId}`,
 | 
			
		||||
    method: 'put',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 添加属性
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function createAttribute(data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes`,
 | 
			
		||||
    method: 'post',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 搜索属性/ 获取所有的属性
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function searchAttributes(params) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes/s`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: params
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getCITypeAttributesByTypeIds(params) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/attributes`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: params
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getCITypeCommonAttributesByTypeIds(params) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/common_attributes`,
 | 
			
		||||
    method: 'get',
 | 
			
		||||
    params: params
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 删除属性
 | 
			
		||||
 * @param attrId
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function deleteAttributesById(attrId) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes/${attrId}`,
 | 
			
		||||
    method: 'delete'
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 绑定ci_type 属性
 | 
			
		||||
 * @param CITypeId
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function createCITypeAttributes(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes`,
 | 
			
		||||
    method: 'post',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 更新ci_type 属性
 | 
			
		||||
 * @param CITypeId
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function updateCITypeAttributesById(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes`,
 | 
			
		||||
    method: 'put',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 删除ci_type 属性
 | 
			
		||||
 * @param CITypeId
 | 
			
		||||
 * @param data
 | 
			
		||||
 * @returns {AxiosPromise}
 | 
			
		||||
 */
 | 
			
		||||
export function deleteCITypeAttributesById(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes`,
 | 
			
		||||
    method: 'delete',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function transferCITypeAttrIndex(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attributes/transfer`,
 | 
			
		||||
    method: 'POST',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function transferCITypeGroupIndex(CITypeId, data) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/${CITypeId}/attribute_groups/transfer`,
 | 
			
		||||
    method: 'POST',
 | 
			
		||||
    data: data
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function canDefineComputed() {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci_types/can_define_computed`,
 | 
			
		||||
    method: 'HEAD',
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function calcComputedAttribute(attr_id) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/attributes/${attr_id}/calc_computed_attribute`,
 | 
			
		||||
    method: 'PUT',
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getAttrPassword(ci_id, attr_id) {
 | 
			
		||||
  return axios({
 | 
			
		||||
    url: `/v0.1/ci/${ci_id}/attributes/${attr_id}/password`,
 | 
			
		||||
    method: 'Get',
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,42 +1,51 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div>
 | 
			
		||||
    <span v-if="!isShow && !isTableLoading">{{ showPassword }}</span>
 | 
			
		||||
    <span v-else>{{ password }}</span>
 | 
			
		||||
    <a
 | 
			
		||||
      :style="{ marginLeft: '10px' }"
 | 
			
		||||
      @click="
 | 
			
		||||
        () => {
 | 
			
		||||
          isShow = !isShow
 | 
			
		||||
        }
 | 
			
		||||
      "
 | 
			
		||||
    ><a-icon
 | 
			
		||||
      :type="isShow ? 'eye-invisible' : 'eye'"
 | 
			
		||||
    /></a>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { mapState } from 'vuex'
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'PasswordField',
 | 
			
		||||
  props: {
 | 
			
		||||
    password: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: '',
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      isShow: false,
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    showPassword() {
 | 
			
		||||
      return '******'
 | 
			
		||||
    },
 | 
			
		||||
    ...mapState('cmdbStore', ['isTableLoading']),
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
<template>
 | 
			
		||||
  <div>
 | 
			
		||||
    <span v-if="!isShow && !isTableLoading">{{ showPassword }}</span>
 | 
			
		||||
    <span v-else>{{ password }}</span>
 | 
			
		||||
    <a :style="{ marginLeft: '10px' }" @click="getPassword"><a-icon :type="isShow ? 'eye-invisible' : 'eye'"/></a>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { mapState } from 'vuex'
 | 
			
		||||
import { getAttrPassword } from '../../api/CITypeAttr'
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'PasswordField',
 | 
			
		||||
  props: {
 | 
			
		||||
    ci_id: {
 | 
			
		||||
      type: Number,
 | 
			
		||||
      default: 0,
 | 
			
		||||
    },
 | 
			
		||||
    attr_id: {
 | 
			
		||||
      type: Number,
 | 
			
		||||
      default: 0,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      isShow: false,
 | 
			
		||||
      password: '',
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    showPassword() {
 | 
			
		||||
      return '******'
 | 
			
		||||
    },
 | 
			
		||||
    ...mapState('cmdbStore', ['isTableLoading']),
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    getPassword() {
 | 
			
		||||
      if (this.isShow) {
 | 
			
		||||
        this.isShow = false
 | 
			
		||||
      } else {
 | 
			
		||||
        getAttrPassword(this.ci_id, this.attr_id).then((res) => {
 | 
			
		||||
          this.password = res.value
 | 
			
		||||
          this.isShow = true
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
 
 | 
			
		||||
@@ -68,7 +68,6 @@ export default {
 | 
			
		||||
        lineNumbers: true,
 | 
			
		||||
        mode: 'python',
 | 
			
		||||
        height: '200px',
 | 
			
		||||
        smartIndent: true,
 | 
			
		||||
        tabSize: 4,
 | 
			
		||||
        lineWrapping: true,
 | 
			
		||||
      },
 | 
			
		||||
 
 | 
			
		||||
@@ -1,26 +1,28 @@
 | 
			
		||||
export const valueTypeMap = {
 | 
			
		||||
  '0': '整数',
 | 
			
		||||
  '1': '浮点数',
 | 
			
		||||
  '2': '文本',
 | 
			
		||||
  '3': 'datetime',
 | 
			
		||||
  '4': 'date',
 | 
			
		||||
  '5': 'time',
 | 
			
		||||
  '6': 'json'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const defautValueColor = [
 | 
			
		||||
  { value: '#d9d9d9' },
 | 
			
		||||
  { value: '#ffccc7' },
 | 
			
		||||
  { value: '#ffd8bf' },
 | 
			
		||||
  { value: '#ffe7ba' },
 | 
			
		||||
  { value: '#fff1b8' },
 | 
			
		||||
  { value: '#f4ffb8' },
 | 
			
		||||
  { value: '#d9f7be' },
 | 
			
		||||
  { value: '#b5f5ec' },
 | 
			
		||||
  { value: '#bae7ff' },
 | 
			
		||||
  { value: '#d6e4ff' },
 | 
			
		||||
  { value: '#efdbff' },
 | 
			
		||||
  { value: '#ffd6e7' },
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
export const defaultBGColors = ['#ffccc7', '#ffd8bf', '#ffe7ba', '#fff1b8', '#d9f7be', '#b5f5ec', '#bae7ff', '#d6e4ff', '#efdbff', '#ffd6e7']
 | 
			
		||||
export const valueTypeMap = {
 | 
			
		||||
  '0': '整数',
 | 
			
		||||
  '1': '浮点数',
 | 
			
		||||
  '2': '文本',
 | 
			
		||||
  '3': '日期时间',
 | 
			
		||||
  '4': '日期',
 | 
			
		||||
  '5': '时间',
 | 
			
		||||
  '6': 'JSON',
 | 
			
		||||
  '7': '密码',
 | 
			
		||||
  '8': '链接'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const defautValueColor = [
 | 
			
		||||
  { value: '#d9d9d9' },
 | 
			
		||||
  { value: '#ffccc7' },
 | 
			
		||||
  { value: '#ffd8bf' },
 | 
			
		||||
  { value: '#ffe7ba' },
 | 
			
		||||
  { value: '#fff1b8' },
 | 
			
		||||
  { value: '#f4ffb8' },
 | 
			
		||||
  { value: '#d9f7be' },
 | 
			
		||||
  { value: '#b5f5ec' },
 | 
			
		||||
  { value: '#bae7ff' },
 | 
			
		||||
  { value: '#d6e4ff' },
 | 
			
		||||
  { value: '#efdbff' },
 | 
			
		||||
  { value: '#ffd6e7' },
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
export const defaultBGColors = ['#ffccc7', '#ffd8bf', '#ffe7ba', '#fff1b8', '#d9f7be', '#b5f5ec', '#bae7ff', '#d6e4ff', '#efdbff', '#ffd6e7']
 | 
			
		||||
 
 | 
			
		||||
@@ -1,176 +1,181 @@
 | 
			
		||||
/* eslint-disable */
 | 
			
		||||
import _ from 'lodash'
 | 
			
		||||
import XLSX from 'xlsx'
 | 
			
		||||
import XLSXS from 'xlsx-js-style'
 | 
			
		||||
export function sum(arr) {
 | 
			
		||||
    if (!arr.length) {
 | 
			
		||||
        return 0
 | 
			
		||||
    }
 | 
			
		||||
    return arr.reduce(function (prev, curr, idx, arr) {
 | 
			
		||||
        return prev + curr
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const strLength = (fData) => {
 | 
			
		||||
 | 
			
		||||
    if (!fData) {
 | 
			
		||||
        return 0
 | 
			
		||||
    }
 | 
			
		||||
    if (fData.length && typeof fData === 'object') {
 | 
			
		||||
        fData = fData.join(' ')
 | 
			
		||||
    }
 | 
			
		||||
    let intLength = 0
 | 
			
		||||
    for (let i = 0; i < fData.length; i++) {
 | 
			
		||||
        if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255)) {
 | 
			
		||||
            intLength = intLength + 2
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            intLength = intLength + 1
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    return Math.floor(intLength * 7)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
String.prototype.pxWidth = function (font) {
 | 
			
		||||
    // re-use canvas object for better performance
 | 
			
		||||
    const canvas = String.prototype.pxWidth.canvas || (String.prototype.pxWidth.canvas = document.createElement("canvas")),
 | 
			
		||||
        context = canvas.getContext("2d");
 | 
			
		||||
 | 
			
		||||
    font && (context.font = font);
 | 
			
		||||
    const metrics = context.measureText(this);
 | 
			
		||||
 | 
			
		||||
    return metrics.width;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getCITableColumns(data, attrList, width = 1600, height) {
 | 
			
		||||
    // 计算出来 主table的列表 布局属性
 | 
			
		||||
 | 
			
		||||
    const _attrList = _.orderBy(attrList, ['is_fixed'], ['desc'])
 | 
			
		||||
    const columns = []
 | 
			
		||||
    for (let attr of _attrList) {
 | 
			
		||||
 | 
			
		||||
        const editRender = { name: 'input' }
 | 
			
		||||
        switch (attr.value_type) {
 | 
			
		||||
            case '0':
 | 
			
		||||
                editRender['props'] = { 'type': 'float' }
 | 
			
		||||
                break
 | 
			
		||||
            case '1':
 | 
			
		||||
                editRender['props'] = { 'type': 'float' }
 | 
			
		||||
                break
 | 
			
		||||
            case '2':
 | 
			
		||||
                editRender['attrs'] = { 'type': 'text' }
 | 
			
		||||
                break
 | 
			
		||||
            case '3':
 | 
			
		||||
                editRender['props'] = { 'type': 'datetime' }
 | 
			
		||||
                break
 | 
			
		||||
            case "4":
 | 
			
		||||
                editRender['props'] = { 'type': 'date' }
 | 
			
		||||
                break
 | 
			
		||||
            case '5':
 | 
			
		||||
                editRender['props'] = { 'type': 'time' }
 | 
			
		||||
                break
 | 
			
		||||
            case '6':
 | 
			
		||||
                editRender['props'] = { 'type': 'text' }
 | 
			
		||||
                break
 | 
			
		||||
            default:
 | 
			
		||||
                editRender['props'] = { 'type': 'text' }
 | 
			
		||||
                break
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (attr.is_choice) {
 | 
			
		||||
            editRender.name = '$select'
 | 
			
		||||
            editRender.options = attr.choice_value ? attr.choice_value.map(item => { return { label: item, value: item } }) : []
 | 
			
		||||
            delete editRender.props
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        columns.push({
 | 
			
		||||
            editRender,
 | 
			
		||||
            title: attr.alias || attr.name,
 | 
			
		||||
            field: attr.name,
 | 
			
		||||
            value_type: attr.value_type,
 | 
			
		||||
            sortable: !!attr.is_sortable,
 | 
			
		||||
            filters: attr.is_choice ? attr.choice_value : null,
 | 
			
		||||
            width: Math.min(Math.max(100, ...data.map(item => strLength(item[attr.name]))), 350),
 | 
			
		||||
            is_link: attr.is_link,
 | 
			
		||||
            is_password: attr.is_password,
 | 
			
		||||
            is_list: attr.is_list,
 | 
			
		||||
            is_choice: attr.is_choice,
 | 
			
		||||
            is_fixed: attr.is_fixed,
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const totalWidth = sum(columns.map(col => col.width))
 | 
			
		||||
    if (totalWidth < width) {
 | 
			
		||||
        columns.map(item => {
 | 
			
		||||
            // if (item.width === 100) {
 | 
			
		||||
            delete item.width
 | 
			
		||||
            // }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
    return columns
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const getPropertyStyle = (attr) => {
 | 
			
		||||
    switch (attr.value_type) {
 | 
			
		||||
        case '0':
 | 
			
		||||
            return { color: '#cf1322', backgroundColor: '#fff1f0' }
 | 
			
		||||
        case '1':
 | 
			
		||||
            return { color: '#d4b106', backgroundColor: '#feffe6' }
 | 
			
		||||
        case '2':
 | 
			
		||||
            return { color: '#d46b08', backgroundColor: '#fff7e6' }
 | 
			
		||||
        case '3':
 | 
			
		||||
            return { color: '#531dab', backgroundColor: '#f9f0ff' }
 | 
			
		||||
        case '4':
 | 
			
		||||
            return { color: '#389e0d', backgroundColor: '#f6ffed' }
 | 
			
		||||
        case '5':
 | 
			
		||||
            return { color: '#08979c', backgroundColor: '#e6fffb' }
 | 
			
		||||
        case '6':
 | 
			
		||||
            return { color: '#c41d7f', backgroundColor: '#fff0f6' }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const getLastLayout = (data, x1 = 0, y1 = 0, w1 = 0) => {
 | 
			
		||||
    const _tempData = _.orderBy(data, ['y', 'x'], ['asc', 'asc'])
 | 
			
		||||
    if (!_tempData.length) {
 | 
			
		||||
        return { xLast: 0, yLast: 0, wLast: 0 }
 | 
			
		||||
    }
 | 
			
		||||
    const { x, y, w } = _tempData[_tempData.length - 1]
 | 
			
		||||
    if (y < y1) {
 | 
			
		||||
        return { xLast: x1, yLast: y1, wLast: w1 }
 | 
			
		||||
    } else if (y > y1) {
 | 
			
		||||
        return { xLast: x, yLast: y, wLast: w }
 | 
			
		||||
    } else {
 | 
			
		||||
        const xLast = _.max([x, x1])
 | 
			
		||||
        return { xLast, yLast: y, wLast: xLast === x ? w : w1 }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 数字加逗号
 | 
			
		||||
export const toThousands = (num = 0) => {
 | 
			
		||||
    return num.toString().replace(/\d+/, function (n) {
 | 
			
		||||
        return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const downloadExcel = (data, fileName = `${moment().format('YYYY-MM-DD HH:mm:ss')}.xls`) => {
 | 
			
		||||
    // STEP 1: Create a new workbook
 | 
			
		||||
    const wb = XLSXS.utils.book_new()
 | 
			
		||||
    // STEP 2: Create data rows and styles
 | 
			
		||||
    const rowArray = data
 | 
			
		||||
    // STEP 3: Create worksheet with rows; Add worksheet to workbook
 | 
			
		||||
    const ws = XLSXS.utils.aoa_to_sheet(rowArray)
 | 
			
		||||
    XLSXS.utils.book_append_sheet(wb, ws, fileName)
 | 
			
		||||
 | 
			
		||||
    let maxColumnNumber = 1 // 默认最大列数
 | 
			
		||||
    rowArray.forEach(item => { if (item.length > maxColumnNumber) { maxColumnNumber = item.length } })
 | 
			
		||||
 | 
			
		||||
    // 添加列宽
 | 
			
		||||
    ws['!cols'] = (rowArray[0].map(item => {
 | 
			
		||||
        return { width: 22 }
 | 
			
		||||
    }))
 | 
			
		||||
    // // 添加行高
 | 
			
		||||
    // ws['!rows'] = [{ 'hpt': 80 }]
 | 
			
		||||
    // STEP 4: Write Excel file to browser  #导出
 | 
			
		||||
    XLSXS.writeFile(wb, fileName + '.xlsx')
 | 
			
		||||
}
 | 
			
		||||
/* eslint-disable */
 | 
			
		||||
import _ from 'lodash'
 | 
			
		||||
import XLSX from 'xlsx'
 | 
			
		||||
import XLSXS from 'xlsx-js-style'
 | 
			
		||||
export function sum(arr) {
 | 
			
		||||
    if (!arr.length) {
 | 
			
		||||
        return 0
 | 
			
		||||
    }
 | 
			
		||||
    return arr.reduce(function (prev, curr, idx, arr) {
 | 
			
		||||
        return prev + curr
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const strLength = (fData) => {
 | 
			
		||||
 | 
			
		||||
    if (!fData) {
 | 
			
		||||
        return 0
 | 
			
		||||
    }
 | 
			
		||||
    if (fData.length && typeof fData === 'object') {
 | 
			
		||||
        fData = fData.join(' ')
 | 
			
		||||
    }
 | 
			
		||||
    let intLength = 0
 | 
			
		||||
    for (let i = 0; i < fData.length; i++) {
 | 
			
		||||
        if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255)) {
 | 
			
		||||
            intLength = intLength + 2
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            intLength = intLength + 1
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    return Math.floor(intLength * 7)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
String.prototype.pxWidth = function (font) {
 | 
			
		||||
    // re-use canvas object for better performance
 | 
			
		||||
    const canvas = String.prototype.pxWidth.canvas || (String.prototype.pxWidth.canvas = document.createElement("canvas")),
 | 
			
		||||
        context = canvas.getContext("2d");
 | 
			
		||||
 | 
			
		||||
    font && (context.font = font);
 | 
			
		||||
    const metrics = context.measureText(this);
 | 
			
		||||
 | 
			
		||||
    return metrics.width;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getCITableColumns(data, attrList, width = 1600, height) {
 | 
			
		||||
    // 计算出来 主table的列表 布局属性
 | 
			
		||||
 | 
			
		||||
    const _attrList = _.orderBy(attrList, ['is_fixed'], ['desc'])
 | 
			
		||||
    const columns = []
 | 
			
		||||
    for (let attr of _attrList) {
 | 
			
		||||
 | 
			
		||||
        const editRender = { name: 'input' }
 | 
			
		||||
        switch (attr.value_type) {
 | 
			
		||||
            case '0':
 | 
			
		||||
                editRender['props'] = { 'type': 'float' }
 | 
			
		||||
                break
 | 
			
		||||
            case '1':
 | 
			
		||||
                editRender['props'] = { 'type': 'float' }
 | 
			
		||||
                break
 | 
			
		||||
            case '2':
 | 
			
		||||
                editRender['attrs'] = { 'type': 'text' }
 | 
			
		||||
                break
 | 
			
		||||
            case '3':
 | 
			
		||||
                editRender['props'] = { 'type': 'datetime' }
 | 
			
		||||
                break
 | 
			
		||||
            case "4":
 | 
			
		||||
                editRender['props'] = { 'type': 'date' }
 | 
			
		||||
                break
 | 
			
		||||
            case '5':
 | 
			
		||||
                editRender['props'] = { 'type': 'time' }
 | 
			
		||||
                break
 | 
			
		||||
            case '6':
 | 
			
		||||
                editRender['props'] = { 'type': 'text' }
 | 
			
		||||
                break
 | 
			
		||||
            default:
 | 
			
		||||
                editRender['props'] = { 'type': 'text' }
 | 
			
		||||
                break
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (attr.is_choice) {
 | 
			
		||||
            editRender.name = '$select'
 | 
			
		||||
            editRender.options = attr.choice_value ? attr.choice_value.map(item => { return { label: item, value: item } }) : []
 | 
			
		||||
            delete editRender.props
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        columns.push({
 | 
			
		||||
            attr_id:attr.id,
 | 
			
		||||
            editRender,
 | 
			
		||||
            title: attr.alias || attr.name,
 | 
			
		||||
            field: attr.name,
 | 
			
		||||
            value_type: attr.value_type,
 | 
			
		||||
            sortable: !!attr.is_sortable,
 | 
			
		||||
            filters: attr.is_choice ? attr.choice_value : null,
 | 
			
		||||
            width: Math.min(Math.max(100, ...data.map(item => strLength(item[attr.name]))), 350),
 | 
			
		||||
            is_link: attr.is_link,
 | 
			
		||||
            is_password: attr.is_password,
 | 
			
		||||
            is_list: attr.is_list,
 | 
			
		||||
            is_choice: attr.is_choice,
 | 
			
		||||
            is_fixed: attr.is_fixed,
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const totalWidth = sum(columns.map(col => col.width))
 | 
			
		||||
    if (totalWidth < width) {
 | 
			
		||||
        columns.map(item => {
 | 
			
		||||
            // if (item.width === 100) {
 | 
			
		||||
            delete item.width
 | 
			
		||||
            // }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
    return columns
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const getPropertyStyle = (attr) => {
 | 
			
		||||
    switch (attr.value_type) {
 | 
			
		||||
        case '0':
 | 
			
		||||
            return { color: '#cf1322', backgroundColor: '#fff1f0' }
 | 
			
		||||
        case '1':
 | 
			
		||||
            return { color: '#d4b106', backgroundColor: '#feffe6' }
 | 
			
		||||
        case '2':
 | 
			
		||||
            return { color: '#d46b08', backgroundColor: '#fff7e6' }
 | 
			
		||||
        case '3':
 | 
			
		||||
            return { color: '#531dab', backgroundColor: '#f9f0ff' }
 | 
			
		||||
        case '4':
 | 
			
		||||
            return { color: '#389e0d', backgroundColor: '#f6ffed' }
 | 
			
		||||
        case '5':
 | 
			
		||||
            return { color: '#08979c', backgroundColor: '#e6fffb' }
 | 
			
		||||
        case '6':
 | 
			
		||||
            return { color: '#c41d7f', backgroundColor: '#fff0f6' }
 | 
			
		||||
        case '7':
 | 
			
		||||
            return { color: '#0390CC', backgroundColor: '#e6fffb' }
 | 
			
		||||
        case '8':
 | 
			
		||||
            return { color: '#144BD9', backgroundColor: '#fff0f6' }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const getLastLayout = (data, x1 = 0, y1 = 0, w1 = 0) => {
 | 
			
		||||
    const _tempData = _.orderBy(data, ['y', 'x'], ['asc', 'asc'])
 | 
			
		||||
    if (!_tempData.length) {
 | 
			
		||||
        return { xLast: 0, yLast: 0, wLast: 0 }
 | 
			
		||||
    }
 | 
			
		||||
    const { x, y, w } = _tempData[_tempData.length - 1]
 | 
			
		||||
    if (y < y1) {
 | 
			
		||||
        return { xLast: x1, yLast: y1, wLast: w1 }
 | 
			
		||||
    } else if (y > y1) {
 | 
			
		||||
        return { xLast: x, yLast: y, wLast: w }
 | 
			
		||||
    } else {
 | 
			
		||||
        const xLast = _.max([x, x1])
 | 
			
		||||
        return { xLast, yLast: y, wLast: xLast === x ? w : w1 }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 数字加逗号
 | 
			
		||||
export const toThousands = (num = 0) => {
 | 
			
		||||
    return num.toString().replace(/\d+/, function (n) {
 | 
			
		||||
        return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const downloadExcel = (data, fileName = `${moment().format('YYYY-MM-DD HH:mm:ss')}.xls`) => {
 | 
			
		||||
    // STEP 1: Create a new workbook
 | 
			
		||||
    const wb = XLSXS.utils.book_new()
 | 
			
		||||
    // STEP 2: Create data rows and styles
 | 
			
		||||
    const rowArray = data
 | 
			
		||||
    // STEP 3: Create worksheet with rows; Add worksheet to workbook
 | 
			
		||||
    const ws = XLSXS.utils.aoa_to_sheet(rowArray)
 | 
			
		||||
    XLSXS.utils.book_append_sheet(wb, ws, fileName)
 | 
			
		||||
 | 
			
		||||
    let maxColumnNumber = 1 // 默认最大列数
 | 
			
		||||
    rowArray.forEach(item => { if (item.length > maxColumnNumber) { maxColumnNumber = item.length } })
 | 
			
		||||
 | 
			
		||||
    // 添加列宽
 | 
			
		||||
    ws['!cols'] = (rowArray[0].map(item => {
 | 
			
		||||
        return { width: 22 }
 | 
			
		||||
    }))
 | 
			
		||||
    // // 添加行高
 | 
			
		||||
    // ws['!rows'] = [{ 'hpt': 80 }]
 | 
			
		||||
    // STEP 4: Write Excel file to browser  #导出
 | 
			
		||||
    XLSXS.writeFile(wb, fileName + '.xlsx')
 | 
			
		||||
}
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -30,7 +30,7 @@
 | 
			
		||||
              :key="attr.name"
 | 
			
		||||
              v-for="attr in group.attributes"
 | 
			
		||||
            >
 | 
			
		||||
              <CiDetailAttrContent :ci="ci" :attr="attr" @refresh="refresh" />
 | 
			
		||||
              <CiDetailAttrContent :ci="ci" :attr="attr" @refresh="refresh" @updateCIByself="updateCIByself" />
 | 
			
		||||
            </el-descriptions-item>
 | 
			
		||||
          </el-descriptions>
 | 
			
		||||
        </div>
 | 
			
		||||
@@ -97,6 +97,7 @@
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import _ from 'lodash'
 | 
			
		||||
import { Descriptions, DescriptionsItem } from 'element-ui'
 | 
			
		||||
import { getCITypeGroupById, getCITypes } from '@/modules/cmdb/api/CIType'
 | 
			
		||||
import { getCIHistory } from '@/modules/cmdb/api/history'
 | 
			
		||||
@@ -292,6 +293,19 @@ export default {
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    updateCIByself(params, editAttrName) {
 | 
			
		||||
      const _ci = { ..._.cloneDeep(this.ci), ...params }
 | 
			
		||||
      this.ci = _ci
 | 
			
		||||
      const _find = this.treeViewsLevels.find((level) => level.name === editAttrName)
 | 
			
		||||
      // 修改的字段为树形视图订阅的字段 则全部reload
 | 
			
		||||
      setTimeout(() => {
 | 
			
		||||
        if (_find) {
 | 
			
		||||
          this.reload()
 | 
			
		||||
        } else {
 | 
			
		||||
          this.handleSearch()
 | 
			
		||||
        }
 | 
			
		||||
      }, 500)
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,359 +1,377 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <CustomDrawer
 | 
			
		||||
    :title="title + CIType.alias"
 | 
			
		||||
    width="800"
 | 
			
		||||
    @close="handleClose"
 | 
			
		||||
    :maskClosable="false"
 | 
			
		||||
    :visible="visible"
 | 
			
		||||
    wrapClassName="create-instance-form"
 | 
			
		||||
    :bodyStyle="{ paddingTop: 0 }"
 | 
			
		||||
    :headerStyle="{ borderBottom: 'none' }"
 | 
			
		||||
  >
 | 
			
		||||
    <div class="custom-drawer-bottom-action">
 | 
			
		||||
      <a-button @click="handleClose">取消</a-button>
 | 
			
		||||
      <a-button type="primary" @click="createInstance">提交</a-button>
 | 
			
		||||
    </div>
 | 
			
		||||
    <template v-if="action === 'create'">
 | 
			
		||||
      <template v-for="group in attributesByGroup">
 | 
			
		||||
        <CreateInstanceFormByGroup
 | 
			
		||||
          :ref="`createInstanceFormByGroup_${group.id}`"
 | 
			
		||||
          :key="group.id || group.name"
 | 
			
		||||
          :group="group"
 | 
			
		||||
          @handleFocusInput="handleFocusInput"
 | 
			
		||||
          :attributeList="attributeList"
 | 
			
		||||
        />
 | 
			
		||||
      </template>
 | 
			
		||||
      <template v-if="parentsType && parentsType.length">
 | 
			
		||||
        <a-divider style="font-size:14px;margin:14px 0;font-weight:700;">模型关系</a-divider>
 | 
			
		||||
        <a-form>
 | 
			
		||||
          <a-row :gutter="24" align="top" type="flex">
 | 
			
		||||
            <a-col :span="12" v-for="item in parentsType" :key="item.id">
 | 
			
		||||
              <a-form-item :label="item.alias || item.name" :colon="false">
 | 
			
		||||
                <a-input-group compact style="width: 100%">
 | 
			
		||||
                  <a-select v-model="parentsForm[item.name].attr">
 | 
			
		||||
                    <a-select-option
 | 
			
		||||
                      :title="attr.alias || attr.name"
 | 
			
		||||
                      v-for="attr in item.attributes"
 | 
			
		||||
                      :key="attr.name"
 | 
			
		||||
                      :value="attr.name"
 | 
			
		||||
                    >
 | 
			
		||||
                      {{ attr.alias || attr.name }}
 | 
			
		||||
                    </a-select-option>
 | 
			
		||||
                  </a-select>
 | 
			
		||||
                  <a-input placeholder="多个值使用,分割" v-model="parentsForm[item.name].value" style="width: 50%" />
 | 
			
		||||
                </a-input-group>
 | 
			
		||||
              </a-form-item>
 | 
			
		||||
            </a-col>
 | 
			
		||||
          </a-row>
 | 
			
		||||
        </a-form>
 | 
			
		||||
      </template>
 | 
			
		||||
    </template>
 | 
			
		||||
    <template v-if="action === 'update'">
 | 
			
		||||
      <a-form :form="form">
 | 
			
		||||
        <p>可根据需要修改字段,当值为<strong>空</strong>时,则该字段<strong>置空</strong></p>
 | 
			
		||||
        <a-row :gutter="24" v-for="list in batchUpdateLists" :key="list.name">
 | 
			
		||||
          <a-col :span="11">
 | 
			
		||||
            <a-form-item>
 | 
			
		||||
              <el-select showSearch size="small" filterable v-model="list.name" placeholder="请选择需要修改的字段">
 | 
			
		||||
                <el-option
 | 
			
		||||
                  v-for="attr in attributeList"
 | 
			
		||||
                  :key="attr.name"
 | 
			
		||||
                  :value="attr.name"
 | 
			
		||||
                  :disabled="batchUpdateLists.findIndex((item) => item.name === attr.name) > -1"
 | 
			
		||||
                  :label="attr.alias || attr.name"
 | 
			
		||||
                >
 | 
			
		||||
                </el-option>
 | 
			
		||||
              </el-select>
 | 
			
		||||
            </a-form-item>
 | 
			
		||||
          </a-col>
 | 
			
		||||
          <a-col :span="11">
 | 
			
		||||
            <a-form-item>
 | 
			
		||||
              <a-select
 | 
			
		||||
                :style="{ width: '100%' }"
 | 
			
		||||
                v-decorator="[list.name, { rules: [{ required: false }] }]"
 | 
			
		||||
                placeholder="请选择"
 | 
			
		||||
                v-if="getFieldType(list.name).split('%%')[0] === 'select'"
 | 
			
		||||
                :mode="getFieldType(list.name).split('%%')[1] === 'multiple' ? 'multiple' : 'default'"
 | 
			
		||||
                showSearch
 | 
			
		||||
                allowClear
 | 
			
		||||
              >
 | 
			
		||||
                <a-select-option
 | 
			
		||||
                  :value="choice[0]"
 | 
			
		||||
                  :key="'New_' + choice + choice_idx"
 | 
			
		||||
                  v-for="(choice, choice_idx) in getSelectFieldOptions(list.name)"
 | 
			
		||||
                >
 | 
			
		||||
                  <span :style="choice[1] ? choice[1].style || {} : {}">
 | 
			
		||||
                    <ops-icon
 | 
			
		||||
                      :style="{ color: choice[1].icon.color }"
 | 
			
		||||
                      v-if="choice[1] && choice[1].icon && choice[1].icon.name"
 | 
			
		||||
                      :type="choice[1].icon.name"
 | 
			
		||||
                    />
 | 
			
		||||
                    {{ choice[0] }}
 | 
			
		||||
                  </span>
 | 
			
		||||
                </a-select-option>
 | 
			
		||||
              </a-select>
 | 
			
		||||
              <a-input-number
 | 
			
		||||
                v-decorator="[list.name, { rules: [{ required: false }] }]"
 | 
			
		||||
                style="width: 100%"
 | 
			
		||||
                v-if="getFieldType(list.name) === 'input_number'"
 | 
			
		||||
              />
 | 
			
		||||
              <a-date-picker
 | 
			
		||||
                v-decorator="[list.name, { rules: [{ required: false }] }]"
 | 
			
		||||
                style="width: 100%"
 | 
			
		||||
                :format="getFieldType(list.name) == 'date' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
 | 
			
		||||
                v-if="getFieldType(list.name) === 'date' || getFieldType(list.name) === 'datetime'"
 | 
			
		||||
                :showTime="getFieldType(list.name) === 'date' ? false : { format: 'HH:mm:ss' }"
 | 
			
		||||
              />
 | 
			
		||||
              <a-input
 | 
			
		||||
                v-if="getFieldType(list.name) === 'input'"
 | 
			
		||||
                @focus="(e) => handleFocusInput(e, list)"
 | 
			
		||||
                v-decorator="[list.name, { rules: [{ required: false }] }]"
 | 
			
		||||
              />
 | 
			
		||||
            </a-form-item>
 | 
			
		||||
          </a-col>
 | 
			
		||||
          <a-col :span="2">
 | 
			
		||||
            <a-form-item>
 | 
			
		||||
              <a :style="{ color: 'red', marginTop: '2px' }" @click="handleDelete(list.name)">
 | 
			
		||||
                <a-icon type="delete"/>
 | 
			
		||||
              </a>
 | 
			
		||||
            </a-form-item>
 | 
			
		||||
          </a-col>
 | 
			
		||||
        </a-row>
 | 
			
		||||
        <a-button type="primary" ghost icon="plus" @click="handleAdd">新增修改字段</a-button>
 | 
			
		||||
      </a-form>
 | 
			
		||||
    </template>
 | 
			
		||||
    <JsonEditor ref="jsonEditor" @jsonEditorOk="jsonEditorOk" />
 | 
			
		||||
  </CustomDrawer>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import moment from 'moment'
 | 
			
		||||
import { Select, Option } from 'element-ui'
 | 
			
		||||
import { getCIType, getCITypeGroupById } from '@/modules/cmdb/api/CIType'
 | 
			
		||||
import { addCI } from '@/modules/cmdb/api/ci'
 | 
			
		||||
import JsonEditor from '../../../components/JsonEditor/jsonEditor.vue'
 | 
			
		||||
import { valueTypeMap } from '../../../utils/const'
 | 
			
		||||
import CreateInstanceFormByGroup from './createInstanceFormByGroup.vue'
 | 
			
		||||
import { getCITypeParent } from '@/modules/cmdb/api/CITypeRelation'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'CreateInstanceForm',
 | 
			
		||||
  components: {
 | 
			
		||||
    ElSelect: Select,
 | 
			
		||||
    ElOption: Option,
 | 
			
		||||
    JsonEditor,
 | 
			
		||||
    CreateInstanceFormByGroup,
 | 
			
		||||
  },
 | 
			
		||||
  props: {
 | 
			
		||||
    typeIdFromRelation: {
 | 
			
		||||
      type: Number,
 | 
			
		||||
      default: 0,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      valueTypeMap,
 | 
			
		||||
      action: '',
 | 
			
		||||
      form: this.$form.createForm(this),
 | 
			
		||||
      visible: false,
 | 
			
		||||
      attributeList: [],
 | 
			
		||||
 | 
			
		||||
      CIType: {},
 | 
			
		||||
 | 
			
		||||
      batchUpdateLists: [],
 | 
			
		||||
      editAttr: null,
 | 
			
		||||
      attributesByGroup: [],
 | 
			
		||||
      parentsType: [],
 | 
			
		||||
      parentsForm: {},
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    title() {
 | 
			
		||||
      return this.action === 'create' ? '创建 ' : '批量修改 '
 | 
			
		||||
    },
 | 
			
		||||
    typeId() {
 | 
			
		||||
      if (this.typeIdFromRelation) {
 | 
			
		||||
        return this.typeIdFromRelation
 | 
			
		||||
      }
 | 
			
		||||
      return this.$router.currentRoute.meta.typeId
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  provide() {
 | 
			
		||||
    return {
 | 
			
		||||
      getFieldType: this.getFieldType,
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  inject: ['attrList'],
 | 
			
		||||
  methods: {
 | 
			
		||||
    moment,
 | 
			
		||||
    async getCIType() {
 | 
			
		||||
      await getCIType(this.typeId).then((res) => {
 | 
			
		||||
        this.CIType = res.ci_types[0]
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    async getAttributeList() {
 | 
			
		||||
      const _attrList = this.attrList()
 | 
			
		||||
      this.attributeList = _attrList.sort((x, y) => y.is_required - x.is_required)
 | 
			
		||||
      await getCITypeGroupById(this.typeId).then((res1) => {
 | 
			
		||||
        const _attributesByGroup = res1.map((g) => {
 | 
			
		||||
          g.attributes = g.attributes.filter((attr) => !attr.is_computed)
 | 
			
		||||
          return g
 | 
			
		||||
        })
 | 
			
		||||
        const attrHasGroupIds = []
 | 
			
		||||
        res1.forEach((g) => {
 | 
			
		||||
          const id = g.attributes.map((attr) => attr.id)
 | 
			
		||||
          attrHasGroupIds.push(...id)
 | 
			
		||||
        })
 | 
			
		||||
        const otherGroupAttr = this.attributeList.filter(
 | 
			
		||||
          (attr) => !attrHasGroupIds.includes(attr.id) && !attr.is_computed
 | 
			
		||||
        )
 | 
			
		||||
        if (otherGroupAttr.length) {
 | 
			
		||||
          _attributesByGroup.push({ id: -1, name: '其他', attributes: otherGroupAttr })
 | 
			
		||||
        }
 | 
			
		||||
        this.attributesByGroup = _attributesByGroup
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    createInstance() {
 | 
			
		||||
      const _this = this
 | 
			
		||||
      if (_this.action === 'update') {
 | 
			
		||||
        this.form.validateFields((err, values) => {
 | 
			
		||||
          if (err) {
 | 
			
		||||
            return
 | 
			
		||||
          }
 | 
			
		||||
          Object.keys(values).forEach((k) => {
 | 
			
		||||
            const _tempFind = this.attributeList.find((item) => item.name === k)
 | 
			
		||||
            if (_tempFind.value_type === '3' && values[k]) {
 | 
			
		||||
              values[k] = values[k].format('YYYY-MM-DD HH:mm:ss')
 | 
			
		||||
            }
 | 
			
		||||
            if (_tempFind.value_type === '4' && values[k]) {
 | 
			
		||||
              values[k] = values[k].format('YYYY-MM-DD')
 | 
			
		||||
            }
 | 
			
		||||
            if (_tempFind.value_type === '6') {
 | 
			
		||||
              values[k] = values[k] ? JSON.parse(values[k]) : undefined
 | 
			
		||||
            }
 | 
			
		||||
          })
 | 
			
		||||
 | 
			
		||||
          _this.$emit('submit', values)
 | 
			
		||||
        })
 | 
			
		||||
      } else {
 | 
			
		||||
        let values = {}
 | 
			
		||||
        for (let i = 0; i < this.attributesByGroup.length; i++) {
 | 
			
		||||
          const data = this.$refs[`createInstanceFormByGroup_${this.attributesByGroup[i].id}`][0].getData()
 | 
			
		||||
          if (data === 'error') {
 | 
			
		||||
            return
 | 
			
		||||
          }
 | 
			
		||||
          values = { ...values, ...data }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Object.keys(values).forEach((k) => {
 | 
			
		||||
          const _tempFind = this.attributeList.find((item) => item.name === k)
 | 
			
		||||
          if (_tempFind.value_type === '3' && values[k]) {
 | 
			
		||||
            values[k] = values[k].format('YYYY-MM-DD HH:mm:ss')
 | 
			
		||||
          }
 | 
			
		||||
          if (_tempFind.value_type === '4' && values[k]) {
 | 
			
		||||
            values[k] = values[k].format('YYYY-MM-DD')
 | 
			
		||||
          }
 | 
			
		||||
          if (_tempFind.value_type === '6') {
 | 
			
		||||
            values[k] = values[k] ? JSON.parse(values[k]) : undefined
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
        values.ci_type = _this.typeId
 | 
			
		||||
        Object.keys(this.parentsForm).forEach((type) => {
 | 
			
		||||
          if (this.parentsForm[type].value) {
 | 
			
		||||
            values[`$${type}.${this.parentsForm[type].attr}`] = this.parentsForm[type].value
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
        addCI(values).then((res) => {
 | 
			
		||||
          _this.$message.success('新增成功!')
 | 
			
		||||
          _this.visible = false
 | 
			
		||||
          _this.$emit('reload', { ci_id: res.ci_id })
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleClose() {
 | 
			
		||||
      this.visible = false
 | 
			
		||||
    },
 | 
			
		||||
    handleOpen(visible, action) {
 | 
			
		||||
      this.visible = visible
 | 
			
		||||
      this.action = action
 | 
			
		||||
      this.$nextTick(() => {
 | 
			
		||||
        this.form.resetFields()
 | 
			
		||||
        Promise.all([this.getCIType(), this.getAttributeList()]).then(() => {
 | 
			
		||||
          this.batchUpdateLists = [{ name: this.attributeList[0].name }]
 | 
			
		||||
        })
 | 
			
		||||
        if (action === 'create') {
 | 
			
		||||
          getCITypeParent(this.typeId).then((res) => {
 | 
			
		||||
            this.parentsType = res.parents
 | 
			
		||||
            const _parentsForm = {}
 | 
			
		||||
            res.parents.forEach((item) => {
 | 
			
		||||
              const _find = item.attributes.find((attr) => attr.id === item.unique_id)
 | 
			
		||||
              _parentsForm[item.name] = { attr: _find.name, value: '' }
 | 
			
		||||
            })
 | 
			
		||||
            this.parentsForm = _parentsForm
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    getFieldType(name) {
 | 
			
		||||
      const _find = this.attributeList.find((item) => item.name === name)
 | 
			
		||||
      if (_find) {
 | 
			
		||||
        if (_find.is_choice) {
 | 
			
		||||
          if (_find.is_list) {
 | 
			
		||||
            return 'select%%multiple'
 | 
			
		||||
          }
 | 
			
		||||
          return 'select'
 | 
			
		||||
        } else if (_find.value_type === '0' || _find.value_type === '1') {
 | 
			
		||||
          return 'input_number'
 | 
			
		||||
        } else if (_find.value_type === '4' || _find.value_type === '3') {
 | 
			
		||||
          return valueTypeMap[_find.value_type]
 | 
			
		||||
        } else {
 | 
			
		||||
          return 'input'
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      return 'input'
 | 
			
		||||
    },
 | 
			
		||||
    getSelectFieldOptions(name) {
 | 
			
		||||
      const _find = this.attributeList.find((item) => item.name === name)
 | 
			
		||||
      if (_find) {
 | 
			
		||||
        return _find.choice_value
 | 
			
		||||
      }
 | 
			
		||||
      return []
 | 
			
		||||
    },
 | 
			
		||||
    handleAdd() {
 | 
			
		||||
      this.batchUpdateLists.push({ name: undefined })
 | 
			
		||||
    },
 | 
			
		||||
    handleDelete(name) {
 | 
			
		||||
      const _idx = this.batchUpdateLists.findIndex((item) => item.name === name)
 | 
			
		||||
      if (_idx > -1) {
 | 
			
		||||
        this.batchUpdateLists.splice(_idx, 1)
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleFocusInput(e, attr) {
 | 
			
		||||
      console.log(attr)
 | 
			
		||||
      const _tempFind = this.attributeList.find((item) => item.name === attr.name)
 | 
			
		||||
      if (_tempFind.value_type === '6') {
 | 
			
		||||
        this.editAttr = attr
 | 
			
		||||
        e.srcElement.blur()
 | 
			
		||||
        const jsonData = this.form.getFieldValue(attr.name)
 | 
			
		||||
        this.$refs.jsonEditor.open(null, null, jsonData ? JSON.parse(jsonData) : {})
 | 
			
		||||
      } else {
 | 
			
		||||
        this.editAttr = null
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    jsonEditorOk(jsonData) {
 | 
			
		||||
      this.form.setFieldsValue({ [this.editAttr.name]: JSON.stringify(jsonData) })
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
<style lang="less">
 | 
			
		||||
.create-instance-form {
 | 
			
		||||
  .ant-form-item {
 | 
			
		||||
    margin-bottom: 5px;
 | 
			
		||||
  }
 | 
			
		||||
  .ant-drawer-body {
 | 
			
		||||
    overflow-y: auto;
 | 
			
		||||
    max-height: calc(100vh - 110px);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
<template>
 | 
			
		||||
  <CustomDrawer
 | 
			
		||||
    :title="title + CIType.alias"
 | 
			
		||||
    width="800"
 | 
			
		||||
    @close="handleClose"
 | 
			
		||||
    :maskClosable="false"
 | 
			
		||||
    :visible="visible"
 | 
			
		||||
    wrapClassName="create-instance-form"
 | 
			
		||||
    :bodyStyle="{ paddingTop: 0 }"
 | 
			
		||||
    :headerStyle="{ borderBottom: 'none' }"
 | 
			
		||||
  >
 | 
			
		||||
    <div class="custom-drawer-bottom-action">
 | 
			
		||||
      <a-button @click="handleClose">取消</a-button>
 | 
			
		||||
      <a-button type="primary" @click="createInstance">提交</a-button>
 | 
			
		||||
    </div>
 | 
			
		||||
    <template v-if="action === 'create'">
 | 
			
		||||
      <template v-for="group in attributesByGroup">
 | 
			
		||||
        <CreateInstanceFormByGroup
 | 
			
		||||
          :ref="`createInstanceFormByGroup_${group.id}`"
 | 
			
		||||
          :key="group.id || group.name"
 | 
			
		||||
          :group="group"
 | 
			
		||||
          @handleFocusInput="handleFocusInput"
 | 
			
		||||
          :attributeList="attributeList"
 | 
			
		||||
        />
 | 
			
		||||
      </template>
 | 
			
		||||
      <template v-if="parentsType && parentsType.length">
 | 
			
		||||
        <a-divider style="font-size:14px;margin:14px 0;font-weight:700;">模型关系</a-divider>
 | 
			
		||||
        <a-form>
 | 
			
		||||
          <a-row :gutter="24" align="top" type="flex">
 | 
			
		||||
            <a-col :span="12" v-for="item in parentsType" :key="item.id">
 | 
			
		||||
              <a-form-item :label="item.alias || item.name" :colon="false">
 | 
			
		||||
                <a-input-group compact style="width: 100%">
 | 
			
		||||
                  <a-select v-model="parentsForm[item.name].attr">
 | 
			
		||||
                    <a-select-option
 | 
			
		||||
                      :title="attr.alias || attr.name"
 | 
			
		||||
                      v-for="attr in item.attributes"
 | 
			
		||||
                      :key="attr.name"
 | 
			
		||||
                      :value="attr.name"
 | 
			
		||||
                    >
 | 
			
		||||
                      {{ attr.alias || attr.name }}
 | 
			
		||||
                    </a-select-option>
 | 
			
		||||
                  </a-select>
 | 
			
		||||
                  <a-input placeholder="多个值使用,分割" v-model="parentsForm[item.name].value" style="width: 50%" />
 | 
			
		||||
                </a-input-group>
 | 
			
		||||
              </a-form-item>
 | 
			
		||||
            </a-col>
 | 
			
		||||
          </a-row>
 | 
			
		||||
        </a-form>
 | 
			
		||||
      </template>
 | 
			
		||||
    </template>
 | 
			
		||||
    <template v-if="action === 'update'">
 | 
			
		||||
      <a-form :form="form">
 | 
			
		||||
        <p>可根据需要修改字段,当值为<strong>空</strong>时,则该字段<strong>置空</strong></p>
 | 
			
		||||
        <a-row :gutter="24" v-for="list in batchUpdateLists" :key="list.name">
 | 
			
		||||
          <a-col :span="11">
 | 
			
		||||
            <a-form-item>
 | 
			
		||||
              <el-select showSearch size="small" filterable v-model="list.name" placeholder="请选择需要修改的字段">
 | 
			
		||||
                <el-option
 | 
			
		||||
                  v-for="attr in attributeList"
 | 
			
		||||
                  :key="attr.name"
 | 
			
		||||
                  :value="attr.name"
 | 
			
		||||
                  :disabled="batchUpdateLists.findIndex((item) => item.name === attr.name) > -1"
 | 
			
		||||
                  :label="attr.alias || attr.name"
 | 
			
		||||
                >
 | 
			
		||||
                </el-option>
 | 
			
		||||
              </el-select>
 | 
			
		||||
            </a-form-item>
 | 
			
		||||
          </a-col>
 | 
			
		||||
          <a-col :span="11">
 | 
			
		||||
            <a-form-item>
 | 
			
		||||
              <a-select
 | 
			
		||||
                :style="{ width: '100%' }"
 | 
			
		||||
                v-decorator="[list.name, { rules: [{ required: false }] }]"
 | 
			
		||||
                placeholder="请选择"
 | 
			
		||||
                v-if="getFieldType(list.name).split('%%')[0] === 'select'"
 | 
			
		||||
                :mode="getFieldType(list.name).split('%%')[1] === 'multiple' ? 'multiple' : 'default'"
 | 
			
		||||
                showSearch
 | 
			
		||||
                allowClear
 | 
			
		||||
              >
 | 
			
		||||
                <a-select-option
 | 
			
		||||
                  :value="choice[0]"
 | 
			
		||||
                  :key="'New_' + choice + choice_idx"
 | 
			
		||||
                  v-for="(choice, choice_idx) in getSelectFieldOptions(list.name)"
 | 
			
		||||
                >
 | 
			
		||||
                  <span :style="choice[1] ? choice[1].style || {} : {}">
 | 
			
		||||
                    <ops-icon
 | 
			
		||||
                      :style="{ color: choice[1].icon.color }"
 | 
			
		||||
                      v-if="choice[1] && choice[1].icon && choice[1].icon.name"
 | 
			
		||||
                      :type="choice[1].icon.name"
 | 
			
		||||
                    />
 | 
			
		||||
                    {{ choice[0] }}
 | 
			
		||||
                  </span>
 | 
			
		||||
                </a-select-option>
 | 
			
		||||
              </a-select>
 | 
			
		||||
              <a-input-number
 | 
			
		||||
                v-decorator="[list.name, { rules: [{ required: false }] }]"
 | 
			
		||||
                style="width: 100%"
 | 
			
		||||
                v-if="getFieldType(list.name) === 'input_number'"
 | 
			
		||||
              />
 | 
			
		||||
              <a-date-picker
 | 
			
		||||
                v-decorator="[list.name, { rules: [{ required: false }] }]"
 | 
			
		||||
                style="width: 100%"
 | 
			
		||||
                :format="getFieldType(list.name) == 'date' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
 | 
			
		||||
                v-if="getFieldType(list.name) === 'date' || getFieldType(list.name) === 'datetime'"
 | 
			
		||||
                :showTime="getFieldType(list.name) === 'date' ? false : { format: 'HH:mm:ss' }"
 | 
			
		||||
              />
 | 
			
		||||
              <a-input
 | 
			
		||||
                v-if="getFieldType(list.name) === 'input'"
 | 
			
		||||
                @focus="(e) => handleFocusInput(e, list)"
 | 
			
		||||
                v-decorator="[list.name, { rules: [{ required: false }] }]"
 | 
			
		||||
              />
 | 
			
		||||
            </a-form-item>
 | 
			
		||||
          </a-col>
 | 
			
		||||
          <a-col :span="2">
 | 
			
		||||
            <a-form-item>
 | 
			
		||||
              <a :style="{ color: 'red', marginTop: '2px' }" @click="handleDelete(list.name)">
 | 
			
		||||
                <a-icon type="delete" />
 | 
			
		||||
              </a>
 | 
			
		||||
            </a-form-item>
 | 
			
		||||
          </a-col>
 | 
			
		||||
        </a-row>
 | 
			
		||||
        <a-button type="primary" ghost icon="plus" @click="handleAdd">新增修改字段</a-button>
 | 
			
		||||
      </a-form>
 | 
			
		||||
    </template>
 | 
			
		||||
    <!-- </a-form> -->
 | 
			
		||||
    <JsonEditor ref="jsonEditor" @jsonEditorOk="jsonEditorOk" />
 | 
			
		||||
  </CustomDrawer>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import moment from 'moment'
 | 
			
		||||
import { Select, Option } from 'element-ui'
 | 
			
		||||
import { getCIType, getCITypeGroupById } from '@/modules/cmdb/api/CIType'
 | 
			
		||||
import { addCI } from '@/modules/cmdb/api/ci'
 | 
			
		||||
import JsonEditor from '../../../components/JsonEditor/jsonEditor.vue'
 | 
			
		||||
import { valueTypeMap } from '../../../utils/const'
 | 
			
		||||
import CreateInstanceFormByGroup from './createInstanceFormByGroup.vue'
 | 
			
		||||
import { getCITypeParent } from '@/modules/cmdb/api/CITypeRelation'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'CreateInstanceForm',
 | 
			
		||||
  components: {
 | 
			
		||||
    ElSelect: Select,
 | 
			
		||||
    ElOption: Option,
 | 
			
		||||
    JsonEditor,
 | 
			
		||||
    CreateInstanceFormByGroup,
 | 
			
		||||
  },
 | 
			
		||||
  props: {
 | 
			
		||||
    typeIdFromRelation: {
 | 
			
		||||
      type: Number,
 | 
			
		||||
      default: 0,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      valueTypeMap,
 | 
			
		||||
      action: '',
 | 
			
		||||
      form: this.$form.createForm(this),
 | 
			
		||||
      visible: false,
 | 
			
		||||
      attributeList: [],
 | 
			
		||||
 | 
			
		||||
      CIType: {},
 | 
			
		||||
 | 
			
		||||
      batchUpdateLists: [],
 | 
			
		||||
      editAttr: null,
 | 
			
		||||
      attributesByGroup: [],
 | 
			
		||||
      parentsType: [],
 | 
			
		||||
      parentsForm: {},
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    title() {
 | 
			
		||||
      return this.action === 'create' ? '创建 ' : '批量修改 '
 | 
			
		||||
    },
 | 
			
		||||
    typeId() {
 | 
			
		||||
      if (this.typeIdFromRelation) {
 | 
			
		||||
        return this.typeIdFromRelation
 | 
			
		||||
      }
 | 
			
		||||
      return this.$router.currentRoute.meta.typeId
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  provide() {
 | 
			
		||||
    return {
 | 
			
		||||
      getFieldType: this.getFieldType,
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  inject: ['attrList'],
 | 
			
		||||
  methods: {
 | 
			
		||||
    moment,
 | 
			
		||||
    async getCIType() {
 | 
			
		||||
      await getCIType(this.typeId).then((res) => {
 | 
			
		||||
        this.CIType = res.ci_types[0]
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    async getAttributeList() {
 | 
			
		||||
      const _attrList = this.attrList()
 | 
			
		||||
      this.attributeList = _attrList.sort((x, y) => y.is_required - x.is_required)
 | 
			
		||||
      await getCITypeGroupById(this.typeId).then((res1) => {
 | 
			
		||||
        const _attributesByGroup = res1.map((g) => {
 | 
			
		||||
          g.attributes = g.attributes.filter((attr) => !attr.is_computed)
 | 
			
		||||
          return g
 | 
			
		||||
        })
 | 
			
		||||
        const attrHasGroupIds = []
 | 
			
		||||
        res1.forEach((g) => {
 | 
			
		||||
          const id = g.attributes.map((attr) => attr.id)
 | 
			
		||||
          attrHasGroupIds.push(...id)
 | 
			
		||||
        })
 | 
			
		||||
        const otherGroupAttr = this.attributeList.filter(
 | 
			
		||||
          (attr) => !attrHasGroupIds.includes(attr.id) && !attr.is_computed
 | 
			
		||||
        )
 | 
			
		||||
        if (otherGroupAttr.length) {
 | 
			
		||||
          _attributesByGroup.push({ id: -1, name: '其他', attributes: otherGroupAttr })
 | 
			
		||||
        }
 | 
			
		||||
        this.attributesByGroup = _attributesByGroup
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    createInstance() {
 | 
			
		||||
      const _this = this
 | 
			
		||||
      if (_this.action === 'update') {
 | 
			
		||||
        this.form.validateFields((err, values) => {
 | 
			
		||||
          if (err) {
 | 
			
		||||
            return
 | 
			
		||||
          }
 | 
			
		||||
          Object.keys(values).forEach((k) => {
 | 
			
		||||
            const _tempFind = this.attributeList.find((item) => item.name === k)
 | 
			
		||||
            if (
 | 
			
		||||
              _tempFind.value_type === '3' &&
 | 
			
		||||
              values[k] &&
 | 
			
		||||
              Object.prototype.toString.call(values[k]) === '[object Object]'
 | 
			
		||||
            ) {
 | 
			
		||||
              values[k] = values[k].format('YYYY-MM-DD HH:mm:ss')
 | 
			
		||||
            }
 | 
			
		||||
            if (
 | 
			
		||||
              _tempFind.value_type === '4' &&
 | 
			
		||||
              values[k] &&
 | 
			
		||||
              Object.prototype.toString.call(values[k]) === '[object Object]'
 | 
			
		||||
            ) {
 | 
			
		||||
              values[k] = values[k].format('YYYY-MM-DD')
 | 
			
		||||
            }
 | 
			
		||||
            if (_tempFind.value_type === '6') {
 | 
			
		||||
              values[k] = values[k] ? JSON.parse(values[k]) : undefined
 | 
			
		||||
            }
 | 
			
		||||
          })
 | 
			
		||||
 | 
			
		||||
          _this.$emit('submit', values)
 | 
			
		||||
        })
 | 
			
		||||
      } else {
 | 
			
		||||
        let values = {}
 | 
			
		||||
        for (let i = 0; i < this.attributesByGroup.length; i++) {
 | 
			
		||||
          const data = this.$refs[`createInstanceFormByGroup_${this.attributesByGroup[i].id}`][0].getData()
 | 
			
		||||
          if (data === 'error') {
 | 
			
		||||
            return
 | 
			
		||||
          }
 | 
			
		||||
          values = { ...values, ...data }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Object.keys(values).forEach((k) => {
 | 
			
		||||
          const _tempFind = this.attributeList.find((item) => item.name === k)
 | 
			
		||||
          if (
 | 
			
		||||
            _tempFind.value_type === '3' &&
 | 
			
		||||
            values[k] &&
 | 
			
		||||
            Object.prototype.toString.call(values[k]) === '[object Object]'
 | 
			
		||||
          ) {
 | 
			
		||||
            values[k] = values[k].format('YYYY-MM-DD HH:mm:ss')
 | 
			
		||||
          }
 | 
			
		||||
          if (
 | 
			
		||||
            _tempFind.value_type === '4' &&
 | 
			
		||||
            values[k] &&
 | 
			
		||||
            Object.prototype.toString.call(values[k]) === '[object Object]'
 | 
			
		||||
          ) {
 | 
			
		||||
            values[k] = values[k].format('YYYY-MM-DD')
 | 
			
		||||
          }
 | 
			
		||||
          if (_tempFind.value_type === '6') {
 | 
			
		||||
            values[k] = values[k] ? JSON.parse(values[k]) : undefined
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
        values.ci_type = _this.typeId
 | 
			
		||||
        console.log(this.parentsForm)
 | 
			
		||||
        Object.keys(this.parentsForm).forEach((type) => {
 | 
			
		||||
          if (this.parentsForm[type].value) {
 | 
			
		||||
            values[`$${type}.${this.parentsForm[type].attr}`] = this.parentsForm[type].value
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
        addCI(values).then((res) => {
 | 
			
		||||
          _this.$message.success('新增成功!')
 | 
			
		||||
          _this.visible = false
 | 
			
		||||
          _this.$emit('reload', { ci_id: res.ci_id })
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleClose() {
 | 
			
		||||
      this.visible = false
 | 
			
		||||
    },
 | 
			
		||||
    handleOpen(visible, action) {
 | 
			
		||||
      this.visible = visible
 | 
			
		||||
      this.action = action
 | 
			
		||||
      this.$nextTick(() => {
 | 
			
		||||
        this.form.resetFields()
 | 
			
		||||
        Promise.all([this.getCIType(), this.getAttributeList()]).then(() => {
 | 
			
		||||
          this.batchUpdateLists = [{ name: this.attributeList[0].name }]
 | 
			
		||||
        })
 | 
			
		||||
        if (action === 'create') {
 | 
			
		||||
          getCITypeParent(this.typeId).then((res) => {
 | 
			
		||||
            this.parentsType = res.parents
 | 
			
		||||
            const _parentsForm = {}
 | 
			
		||||
            res.parents.forEach((item) => {
 | 
			
		||||
              const _find = item.attributes.find((attr) => attr.id === item.unique_id)
 | 
			
		||||
              _parentsForm[item.name] = { attr: _find.name, value: '' }
 | 
			
		||||
            })
 | 
			
		||||
            this.parentsForm = _parentsForm
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    getFieldType(name) {
 | 
			
		||||
      const _find = this.attributeList.find((item) => item.name === name)
 | 
			
		||||
      if (_find) {
 | 
			
		||||
        if (_find.is_choice) {
 | 
			
		||||
          if (_find.is_list) {
 | 
			
		||||
            return 'select%%multiple'
 | 
			
		||||
          }
 | 
			
		||||
          return 'select'
 | 
			
		||||
        } else if (_find.value_type === '0' || _find.value_type === '1') {
 | 
			
		||||
          return 'input_number'
 | 
			
		||||
        } else if (_find.value_type === '4' || _find.value_type === '3') {
 | 
			
		||||
          return valueTypeMap[_find.value_type]
 | 
			
		||||
        } else {
 | 
			
		||||
          return 'input'
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      return 'input'
 | 
			
		||||
    },
 | 
			
		||||
    getSelectFieldOptions(name) {
 | 
			
		||||
      const _find = this.attributeList.find((item) => item.name === name)
 | 
			
		||||
      if (_find) {
 | 
			
		||||
        return _find.choice_value
 | 
			
		||||
      }
 | 
			
		||||
      return []
 | 
			
		||||
    },
 | 
			
		||||
    handleAdd() {
 | 
			
		||||
      this.batchUpdateLists.push({ name: undefined })
 | 
			
		||||
    },
 | 
			
		||||
    handleDelete(name) {
 | 
			
		||||
      const _idx = this.batchUpdateLists.findIndex((item) => item.name === name)
 | 
			
		||||
      if (_idx > -1) {
 | 
			
		||||
        this.batchUpdateLists.splice(_idx, 1)
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleFocusInput(e, attr) {
 | 
			
		||||
      console.log(attr)
 | 
			
		||||
      const _tempFind = this.attributeList.find((item) => item.name === attr.name)
 | 
			
		||||
      if (_tempFind.value_type === '6') {
 | 
			
		||||
        this.editAttr = attr
 | 
			
		||||
        e.srcElement.blur()
 | 
			
		||||
        const jsonData = this.form.getFieldValue(attr.name)
 | 
			
		||||
        this.$refs.jsonEditor.open(null, null, jsonData ? JSON.parse(jsonData) : {})
 | 
			
		||||
      } else {
 | 
			
		||||
        this.editAttr = null
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    jsonEditorOk(jsonData) {
 | 
			
		||||
      this.form.setFieldsValue({ [this.editAttr.name]: JSON.stringify(jsonData) })
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
<style lang="less">
 | 
			
		||||
.create-instance-form {
 | 
			
		||||
  .ant-form-item {
 | 
			
		||||
    margin-bottom: 5px;
 | 
			
		||||
  }
 | 
			
		||||
  .ant-drawer-body {
 | 
			
		||||
    overflow-y: auto;
 | 
			
		||||
    max-height: calc(100vh - 110px);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,215 +1,225 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <CustomDrawer
 | 
			
		||||
    :visible="visible"
 | 
			
		||||
    :hasFooter="false"
 | 
			
		||||
    @close="
 | 
			
		||||
      () => {
 | 
			
		||||
        visible = false
 | 
			
		||||
      }
 | 
			
		||||
    "
 | 
			
		||||
    title="属性说明"
 | 
			
		||||
    width="72%"
 | 
			
		||||
    :bodyStyle="{ height: '100vh' }"
 | 
			
		||||
  >
 | 
			
		||||
    <vxe-toolbar>
 | 
			
		||||
      <template #buttons>
 | 
			
		||||
        <a-input
 | 
			
		||||
          v-model="searchKey"
 | 
			
		||||
          :style="{ display: 'inline-block', width: '244px' }"
 | 
			
		||||
          class="ops-input ops-input-radius"
 | 
			
		||||
          type="search"
 | 
			
		||||
          placeholder="搜索 名称 | 别名"
 | 
			
		||||
          @keyup="searchAttributes"
 | 
			
		||||
        >
 | 
			
		||||
          <a-icon type="search" slot="suffix" />
 | 
			
		||||
        </a-input>
 | 
			
		||||
      </template>
 | 
			
		||||
    </vxe-toolbar>
 | 
			
		||||
 | 
			
		||||
    <a-spin :spinning="loading">
 | 
			
		||||
      <vxe-table
 | 
			
		||||
        resizable
 | 
			
		||||
        border
 | 
			
		||||
        size="mini"
 | 
			
		||||
        :height="windowHeight - 160"
 | 
			
		||||
        :data="list"
 | 
			
		||||
        :scroll-x="{ enabled: true, gt: 0 }"
 | 
			
		||||
        show-overflow
 | 
			
		||||
        show-header-overflow
 | 
			
		||||
        align="center"
 | 
			
		||||
        highlight-hover-row
 | 
			
		||||
        class="ops-stripe-table"
 | 
			
		||||
      >
 | 
			
		||||
        <vxe-column
 | 
			
		||||
          v-for="(column, index) in columns"
 | 
			
		||||
          :field="column.field"
 | 
			
		||||
          :title="column.title"
 | 
			
		||||
          :min-width="column.width"
 | 
			
		||||
          :align="column.align"
 | 
			
		||||
          :key="column.field"
 | 
			
		||||
          :fixed="index < 3 ? 'left' : ''"
 | 
			
		||||
          :sortable="index < 3 ? true : false"
 | 
			
		||||
          :title-help="column.help !== null ? { message: column.help } : null"
 | 
			
		||||
          :filters="
 | 
			
		||||
            index < 2 ? null: index === 2
 | 
			
		||||
              ? valueTypeFilters: [{ label: '是', value: true }, { label: '否', value: false },]"
 | 
			
		||||
          type="html"
 | 
			
		||||
        >
 | 
			
		||||
          <template #default="{ row }">
 | 
			
		||||
            <span v-if="column.field !== 'name' && column.field !== 'alias' && column.field !== 'value_type'">
 | 
			
		||||
              <a-icon :style="{ color: '#1fb51f' }" type="check" v-if="row[column.field]" />
 | 
			
		||||
            </span>
 | 
			
		||||
            <span v-else-if="column.field === 'value_type'" v-html="valueTypeMap[row.value_type]"> </span>
 | 
			
		||||
            <span v-else v-html="row[column.field]"> </span>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
      </vxe-table>
 | 
			
		||||
    </a-spin>
 | 
			
		||||
  </CustomDrawer>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import XEUtils from 'xe-utils'
 | 
			
		||||
import { getCITypeAttributesByName } from '@/modules/cmdb/api/CITypeAttr'
 | 
			
		||||
import { valueTypeMap } from '@/modules/cmdb/utils/const'
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'MetadataDrawer',
 | 
			
		||||
  data() {
 | 
			
		||||
    const columns = [
 | 
			
		||||
      {
 | 
			
		||||
        field: 'name',
 | 
			
		||||
        title: '名称',
 | 
			
		||||
        width: 150,
 | 
			
		||||
        align: 'left',
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'alias',
 | 
			
		||||
        title: '别名',
 | 
			
		||||
        width: 150,
 | 
			
		||||
        align: 'left',
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'value_type',
 | 
			
		||||
        title: '类型',
 | 
			
		||||
        width: 100,
 | 
			
		||||
        align: 'left',
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_index',
 | 
			
		||||
        title: '是否索引',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '加快检索, 可以全文搜索, 无需使用条件过滤\n\n json目前不支持建索引 \n\n文本字符长度超过190不能建索引',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'default_show',
 | 
			
		||||
        title: '默认显示',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '订阅CI,默认显示在table里的属性',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_unique',
 | 
			
		||||
        title: '是否唯一',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_choice',
 | 
			
		||||
        title: '是否选择',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '表现形式是下拉框, 值必须在预定义值里',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_list',
 | 
			
		||||
        title: '是否列表',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '多值, 比如内网IP',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_sortable',
 | 
			
		||||
        title: '可排序',
 | 
			
		||||
        width: 100,
 | 
			
		||||
        help: '仅针对前端',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_password',
 | 
			
		||||
        title: '是否密码',
 | 
			
		||||
        width: 100,
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_link',
 | 
			
		||||
        title: '是否链接',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_computed',
 | 
			
		||||
        title: '计算属性',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '模型的其他属性通过表达式的方式计算出来\n\n一个代码片段计算返回的值',
 | 
			
		||||
      },
 | 
			
		||||
    ]
 | 
			
		||||
    return {
 | 
			
		||||
      columns,
 | 
			
		||||
      visible: false,
 | 
			
		||||
      list: [],
 | 
			
		||||
      tableData: [],
 | 
			
		||||
      loading: false,
 | 
			
		||||
      valueTypeMap,
 | 
			
		||||
      valueTypeFilters: [],
 | 
			
		||||
      searchKey: '',
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    windowHeight() {
 | 
			
		||||
      return this.$store.state.windowHeight
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  created: function () {
 | 
			
		||||
    this.valueTypeFilters = Object.keys(this.valueTypeMap).map((key) => {
 | 
			
		||||
      return { label: this.valueTypeMap[key], value: key }
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    open(typeId) {
 | 
			
		||||
      this.visible = true
 | 
			
		||||
      this.typeId = typeId
 | 
			
		||||
      this.getAttrs()
 | 
			
		||||
    },
 | 
			
		||||
    async getAttrs() {
 | 
			
		||||
      this.loading = true
 | 
			
		||||
      const { attributes = [] } = await getCITypeAttributesByName(this.typeId)
 | 
			
		||||
      this.tableData = attributes
 | 
			
		||||
      this.loading = false
 | 
			
		||||
      this.searchAttributes()
 | 
			
		||||
    },
 | 
			
		||||
    searchAttributes() {
 | 
			
		||||
      const filterName = XEUtils.toValueString(this.searchKey).trim().toLowerCase()
 | 
			
		||||
      if (filterName) {
 | 
			
		||||
        const filterRE = new RegExp(filterName, 'gi')
 | 
			
		||||
        const searchProps = ['name', 'alias', 'value_type']
 | 
			
		||||
        const rest = this.tableData.filter((item) =>
 | 
			
		||||
          searchProps.some((key) => XEUtils.toValueString(item[key]).toLowerCase().indexOf(filterName) > -1)
 | 
			
		||||
        )
 | 
			
		||||
        this.list = rest.map((row) => {
 | 
			
		||||
          const item = Object.assign({}, row)
 | 
			
		||||
          searchProps.forEach((key) => {
 | 
			
		||||
            item[key] = XEUtils.toValueString(item[key]).replace(
 | 
			
		||||
              filterRE,
 | 
			
		||||
              (match) => `<span style='background: yellow'>${match}</span>`
 | 
			
		||||
            )
 | 
			
		||||
          })
 | 
			
		||||
          return item
 | 
			
		||||
        })
 | 
			
		||||
      } else {
 | 
			
		||||
        this.list = this.tableData
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
<template>
 | 
			
		||||
  <CustomDrawer
 | 
			
		||||
    :visible="visible"
 | 
			
		||||
    :hasFooter="false"
 | 
			
		||||
    @close="
 | 
			
		||||
      () => {
 | 
			
		||||
        visible = false
 | 
			
		||||
      }
 | 
			
		||||
    "
 | 
			
		||||
    title="属性说明"
 | 
			
		||||
    width="72%"
 | 
			
		||||
    :bodyStyle="{ height: '100vh' }"
 | 
			
		||||
  >
 | 
			
		||||
    <vxe-toolbar>
 | 
			
		||||
      <template #buttons>
 | 
			
		||||
        <a-input
 | 
			
		||||
          v-model="searchKey"
 | 
			
		||||
          :style="{ display: 'inline-block', width: '244px' }"
 | 
			
		||||
          class="ops-input ops-input-radius"
 | 
			
		||||
          type="search"
 | 
			
		||||
          placeholder="搜索 名称 | 别名"
 | 
			
		||||
          @keyup="searchAttributes"
 | 
			
		||||
        >
 | 
			
		||||
          <a-icon type="search" slot="suffix" />
 | 
			
		||||
        </a-input>
 | 
			
		||||
      </template>
 | 
			
		||||
    </vxe-toolbar>
 | 
			
		||||
 | 
			
		||||
    <a-spin :spinning="loading">
 | 
			
		||||
      <vxe-table
 | 
			
		||||
        resizable
 | 
			
		||||
        border
 | 
			
		||||
        size="mini"
 | 
			
		||||
        :height="windowHeight - 160"
 | 
			
		||||
        :data="list"
 | 
			
		||||
        :scroll-x="{ enabled: true, gt: 0 }"
 | 
			
		||||
        show-overflow
 | 
			
		||||
        show-header-overflow
 | 
			
		||||
        align="center"
 | 
			
		||||
        highlight-hover-row
 | 
			
		||||
        class="ops-stripe-table"
 | 
			
		||||
      >
 | 
			
		||||
        <vxe-column
 | 
			
		||||
          v-for="(column, index) in columns"
 | 
			
		||||
          :field="column.field"
 | 
			
		||||
          :title="column.title"
 | 
			
		||||
          :min-width="column.width"
 | 
			
		||||
          :align="column.align"
 | 
			
		||||
          :key="column.field"
 | 
			
		||||
          :fixed="index < 3 ? 'left' : ''"
 | 
			
		||||
          :sortable="index < 3 ? true : false"
 | 
			
		||||
          :title-help="column.help !== null ? { message: column.help } : null"
 | 
			
		||||
          :filters="
 | 
			
		||||
            index < 2
 | 
			
		||||
              ? null
 | 
			
		||||
              : index === 2
 | 
			
		||||
                ? valueTypeFilters
 | 
			
		||||
                : [
 | 
			
		||||
                  { label: '是', value: true },
 | 
			
		||||
                  { label: '否', value: false },
 | 
			
		||||
                ]
 | 
			
		||||
          "
 | 
			
		||||
          type="html"
 | 
			
		||||
        >
 | 
			
		||||
          <template #default="{ row }">
 | 
			
		||||
            <span v-if="column.field !== 'name' && column.field !== 'alias' && column.field !== 'value_type'">
 | 
			
		||||
              <a-icon :style="{ color: '#1fb51f' }" type="check" v-if="row[column.field]" />
 | 
			
		||||
            </span>
 | 
			
		||||
            <span v-else-if="column.field === 'value_type'" v-html="valueTypeMap[row.value_type]"> </span>
 | 
			
		||||
            <span v-else v-html="row[column.field]"> </span>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
      </vxe-table>
 | 
			
		||||
    </a-spin>
 | 
			
		||||
  </CustomDrawer>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import XEUtils from 'xe-utils'
 | 
			
		||||
import { getCITypeAttributesByName } from '@/modules/cmdb/api/CITypeAttr'
 | 
			
		||||
import { valueTypeMap } from '@/modules/cmdb/utils/const'
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'MetadataDrawer',
 | 
			
		||||
  data() {
 | 
			
		||||
    const columns = [
 | 
			
		||||
      {
 | 
			
		||||
        field: 'name',
 | 
			
		||||
        title: '名称',
 | 
			
		||||
        width: 150,
 | 
			
		||||
        align: 'left',
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'alias',
 | 
			
		||||
        title: '别名',
 | 
			
		||||
        width: 150,
 | 
			
		||||
        align: 'left',
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'value_type',
 | 
			
		||||
        title: '类型',
 | 
			
		||||
        width: 100,
 | 
			
		||||
        align: 'left',
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_index',
 | 
			
		||||
        title: '是否索引',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '加快检索, 可以全文搜索, 无需使用条件过滤\n\n json目前不支持建索引 \n\n文本字符长度超过190不能建索引',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'default_show',
 | 
			
		||||
        title: '默认显示',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '订阅CI,默认显示在table里的属性',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_unique',
 | 
			
		||||
        title: '是否唯一',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: null,
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_choice',
 | 
			
		||||
        title: '是否选择',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '表现形式是下拉框, 值必须在预定义值里',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_list',
 | 
			
		||||
        title: '是否列表',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '多值, 比如内网IP',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_sortable',
 | 
			
		||||
        title: '可排序',
 | 
			
		||||
        width: 100,
 | 
			
		||||
        help: '仅针对前端',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        field: 'is_computed',
 | 
			
		||||
        title: '计算属性',
 | 
			
		||||
        width: 110,
 | 
			
		||||
        help: '模型的其他属性通过表达式的方式计算出来\n\n一个代码片段计算返回的值',
 | 
			
		||||
      },
 | 
			
		||||
    ]
 | 
			
		||||
    return {
 | 
			
		||||
      columns,
 | 
			
		||||
      visible: false,
 | 
			
		||||
      list: [],
 | 
			
		||||
      tableData: [],
 | 
			
		||||
      loading: false,
 | 
			
		||||
      valueTypeMap,
 | 
			
		||||
      valueTypeFilters: [],
 | 
			
		||||
      searchKey: '',
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    windowHeight() {
 | 
			
		||||
      return this.$store.state.windowHeight
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  created: function() {
 | 
			
		||||
    this.valueTypeFilters = Object.keys(this.valueTypeMap).map((key) => {
 | 
			
		||||
      return { label: this.valueTypeMap[key], value: key }
 | 
			
		||||
    })
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    open(typeId) {
 | 
			
		||||
      this.visible = true
 | 
			
		||||
      this.typeId = typeId
 | 
			
		||||
      this.getAttrs()
 | 
			
		||||
    },
 | 
			
		||||
    async getAttrs() {
 | 
			
		||||
      this.loading = true
 | 
			
		||||
      const { attributes = [] } = await getCITypeAttributesByName(this.typeId)
 | 
			
		||||
      this.tableData = attributes.map((attr) => {
 | 
			
		||||
        if (attr.is_password) {
 | 
			
		||||
          attr.value_type = '7'
 | 
			
		||||
        }
 | 
			
		||||
        if (attr.is_link) {
 | 
			
		||||
          attr.value_type = '8'
 | 
			
		||||
        }
 | 
			
		||||
        return attr
 | 
			
		||||
      })
 | 
			
		||||
      this.loading = false
 | 
			
		||||
      this.searchAttributes()
 | 
			
		||||
    },
 | 
			
		||||
    searchAttributes() {
 | 
			
		||||
      const filterName = XEUtils.toValueString(this.searchKey)
 | 
			
		||||
        .trim()
 | 
			
		||||
        .toLowerCase()
 | 
			
		||||
      if (filterName) {
 | 
			
		||||
        const filterRE = new RegExp(filterName, 'gi')
 | 
			
		||||
        const searchProps = ['name', 'alias', 'value_type']
 | 
			
		||||
        const rest = this.tableData.filter((item) =>
 | 
			
		||||
          searchProps.some(
 | 
			
		||||
            (key) =>
 | 
			
		||||
              XEUtils.toValueString(item[key])
 | 
			
		||||
                .toLowerCase()
 | 
			
		||||
                .indexOf(filterName) > -1
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
        this.list = rest.map((row) => {
 | 
			
		||||
          const item = Object.assign({}, row)
 | 
			
		||||
          searchProps.forEach((key) => {
 | 
			
		||||
            item[key] = XEUtils.toValueString(item[key]).replace(
 | 
			
		||||
              filterRE,
 | 
			
		||||
              (match) => `<span style='background: yellow'>${match}</span>`
 | 
			
		||||
            )
 | 
			
		||||
          })
 | 
			
		||||
          return item
 | 
			
		||||
        })
 | 
			
		||||
      } else {
 | 
			
		||||
        this.list = this.tableData
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,234 +1,299 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <span :id="`ci-detail-attr-${attr.name}`">
 | 
			
		||||
    <span v-if="!isEdit || attr.value_type === '6'">
 | 
			
		||||
      <template v-if="attr.value_type === '6'">{{ JSON.stringify(ci[attr.name] || {}) }}</template>
 | 
			
		||||
      <template v-else-if="attr.is_choice">
 | 
			
		||||
        <template v-if="attr.is_list">
 | 
			
		||||
          <span
 | 
			
		||||
            v-for="value in ci[attr.name]"
 | 
			
		||||
            :key="value"
 | 
			
		||||
            :style="{
 | 
			
		||||
              borderRadius: '4px',
 | 
			
		||||
              padding: '1px 5px',
 | 
			
		||||
              margin: '2px',
 | 
			
		||||
              ...getChoiceValueStyle(attr, value),
 | 
			
		||||
            }"
 | 
			
		||||
          >
 | 
			
		||||
            <ops-icon
 | 
			
		||||
              :style="{ color: getChoiceValueIcon(attr, value).color }"
 | 
			
		||||
              :type="getChoiceValueIcon(attr, value).name"
 | 
			
		||||
            />
 | 
			
		||||
            {{ value }}</span
 | 
			
		||||
          >
 | 
			
		||||
        </template>
 | 
			
		||||
        <span
 | 
			
		||||
          v-else
 | 
			
		||||
          :style="{
 | 
			
		||||
            borderRadius: '4px',
 | 
			
		||||
            padding: '1px 5px',
 | 
			
		||||
            margin: '2px 0',
 | 
			
		||||
            ...getChoiceValueStyle(attr, ci[attr.name]),
 | 
			
		||||
          }"
 | 
			
		||||
        >
 | 
			
		||||
          <ops-icon
 | 
			
		||||
            :style="{ color: getChoiceValueIcon(attr, ci[attr.name]).color }"
 | 
			
		||||
            :type="getChoiceValueIcon(attr, ci[attr.name]).name"
 | 
			
		||||
          />
 | 
			
		||||
          {{ ci[attr.name] }}
 | 
			
		||||
        </span>
 | 
			
		||||
      </template>
 | 
			
		||||
      <template v-else>{{ getName(ci[attr.name]) }}</template>
 | 
			
		||||
    </span>
 | 
			
		||||
    <template v-else>
 | 
			
		||||
      <a-form :form="form">
 | 
			
		||||
        <a-form-item label="" :colon="false">
 | 
			
		||||
          <a-select
 | 
			
		||||
            :style="{ width: '100%' }"
 | 
			
		||||
            v-decorator="[
 | 
			
		||||
              attr.name,
 | 
			
		||||
              {
 | 
			
		||||
                rules: [{ required: attr.is_required }],
 | 
			
		||||
              },
 | 
			
		||||
            ]"
 | 
			
		||||
            placeholder="请选择"
 | 
			
		||||
            v-if="attr.is_choice"
 | 
			
		||||
            :mode="attr.is_list ? 'multiple' : 'default'"
 | 
			
		||||
            :multiple="attr.is_list"
 | 
			
		||||
            showSearch
 | 
			
		||||
            allowClear
 | 
			
		||||
            size="small"
 | 
			
		||||
            :getPopupContainer="(trigger) => trigger.parentElement"
 | 
			
		||||
          >
 | 
			
		||||
            <a-select-option
 | 
			
		||||
              :value="choice[0]"
 | 
			
		||||
              :key="'New_' + attr.name + choice_idx"
 | 
			
		||||
              v-for="(choice, choice_idx) in attr.choice_value"
 | 
			
		||||
            >
 | 
			
		||||
              <span :style="choice[1] ? choice[1].style || {} : {}">
 | 
			
		||||
                <ops-icon
 | 
			
		||||
                  :style="{ color: choice[1].icon.color }"
 | 
			
		||||
                  v-if="choice[1] && choice[1].icon && choice[1].icon.name"
 | 
			
		||||
                  :type="choice[1].icon.name"
 | 
			
		||||
                />
 | 
			
		||||
                {{ choice[0] }}
 | 
			
		||||
              </span>
 | 
			
		||||
            </a-select-option>
 | 
			
		||||
          </a-select>
 | 
			
		||||
          <a-input-number
 | 
			
		||||
            size="small"
 | 
			
		||||
            v-decorator="[
 | 
			
		||||
              attr.name,
 | 
			
		||||
              {
 | 
			
		||||
                rules: [{ required: attr.is_required }],
 | 
			
		||||
              },
 | 
			
		||||
            ]"
 | 
			
		||||
            style="width: 100%"
 | 
			
		||||
            v-else-if="attr.value_type === '0' || attr.value_type === '1'"
 | 
			
		||||
          />
 | 
			
		||||
          <a-date-picker
 | 
			
		||||
            size="small"
 | 
			
		||||
            v-decorator="[
 | 
			
		||||
              attr.name,
 | 
			
		||||
              {
 | 
			
		||||
                rules: [{ required: attr.is_required }],
 | 
			
		||||
              },
 | 
			
		||||
            ]"
 | 
			
		||||
            style="width: 100%"
 | 
			
		||||
            :format="attr.value_type === '4' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
 | 
			
		||||
            :valueFormat="attr.value_type === '4' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
 | 
			
		||||
            v-else-if="attr.value_type === '4' || attr.value_type === '3'"
 | 
			
		||||
            :showTime="attr.value_type === '4' ? false : { format: 'HH:mm:ss' }"
 | 
			
		||||
          />
 | 
			
		||||
          <a-input
 | 
			
		||||
            size="small"
 | 
			
		||||
            v-decorator="[
 | 
			
		||||
              attr.name,
 | 
			
		||||
              {
 | 
			
		||||
                validateTrigger: ['submit'],
 | 
			
		||||
                rules: [{ required: attr.is_required }],
 | 
			
		||||
              },
 | 
			
		||||
            ]"
 | 
			
		||||
            style="width: 100%"
 | 
			
		||||
            v-else
 | 
			
		||||
          />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-form>
 | 
			
		||||
    </template>
 | 
			
		||||
    <a v-if="!isEdit && !attr.is_computed" @click="handleEdit" :style="{ opacity: 0 }"><a-icon type="edit"/></a>
 | 
			
		||||
    <JsonEditor ref="jsonEditor" @jsonEditorOk="jsonEditorOk" />
 | 
			
		||||
  </span>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import _ from 'lodash'
 | 
			
		||||
import moment from 'moment'
 | 
			
		||||
import { updateCI } from '@/modules/cmdb/api/ci'
 | 
			
		||||
import JsonEditor from '../../../components/JsonEditor/jsonEditor.vue'
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'CiDetailAttrContent',
 | 
			
		||||
  components: { JsonEditor },
 | 
			
		||||
  props: {
 | 
			
		||||
    ci: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
    attr: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      isEdit: false,
 | 
			
		||||
      form: this.$form.createForm(this, this.attr.name),
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  mounted() {
 | 
			
		||||
    document.addEventListener('click', this.eventListener)
 | 
			
		||||
  },
 | 
			
		||||
  beforeDestroy() {
 | 
			
		||||
    document.removeEventListener('click', this.eventListener)
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    moment,
 | 
			
		||||
    eventListener(e) {
 | 
			
		||||
      const datePickerContainer = document.getElementsByClassName('ant-calendar-picker-container')
 | 
			
		||||
      if (this.isEdit && !datePickerContainer.length) {
 | 
			
		||||
        const dom = document.getElementById(`ci-detail-attr-${this.attr.name}`)
 | 
			
		||||
        e.stopPropagation()
 | 
			
		||||
        e.preventDefault()
 | 
			
		||||
        if (dom) {
 | 
			
		||||
          const isSelf = dom.contains(e.target)
 | 
			
		||||
          if (!isSelf) {
 | 
			
		||||
            this.handleCloseEdit()
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleEdit(e) {
 | 
			
		||||
      e.stopPropagation()
 | 
			
		||||
      e.preventDefault()
 | 
			
		||||
      if (this.attr.value_type === '6') {
 | 
			
		||||
        const jsonData = this.ci[this.attr.name]
 | 
			
		||||
        this.$refs.jsonEditor.open(null, null, jsonData || {})
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      this.isEdit = true
 | 
			
		||||
      this.$nextTick(() => {
 | 
			
		||||
        if (this.attr.is_list && !this.attr.is_choice) {
 | 
			
		||||
          this.form.setFieldsValue({
 | 
			
		||||
            [`${this.attr.name}`]: this.ci[this.attr.name].join(',') || null,
 | 
			
		||||
          })
 | 
			
		||||
          return
 | 
			
		||||
        }
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          [`${this.attr.name}`]: this.ci[this.attr.name] ?? null,
 | 
			
		||||
        })
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    async handleCloseEdit() {
 | 
			
		||||
      const newData = this.form.getFieldValue(this.attr.name)
 | 
			
		||||
      if (!_.isEqual(this.ci[this.attr.name], newData)) {
 | 
			
		||||
        await updateCI(this.ci._id, { [`${this.attr.name}`]: newData })
 | 
			
		||||
          .then(() => {
 | 
			
		||||
            this.$message.success('更新成功!')
 | 
			
		||||
          })
 | 
			
		||||
          .finally(() => {
 | 
			
		||||
            this.$emit('refresh', this.attr.name)
 | 
			
		||||
          })
 | 
			
		||||
      }
 | 
			
		||||
      this.isEdit = false
 | 
			
		||||
    },
 | 
			
		||||
    jsonEditorOk(jsonData) {
 | 
			
		||||
      if (!_.isEqual(this.ci[this.attr.name], jsonData)) {
 | 
			
		||||
        updateCI(this.ci._id, { [`${this.attr.name}`]: jsonData })
 | 
			
		||||
          .then(() => {
 | 
			
		||||
            this.$message.success('更新成功!')
 | 
			
		||||
          })
 | 
			
		||||
          .finally(() => {
 | 
			
		||||
            this.$emit('refresh', this.attr.name)
 | 
			
		||||
          })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    getChoiceValueStyle(col, colValue) {
 | 
			
		||||
      const _find = col.choice_value.find((item) => String(item[0]) === String(colValue))
 | 
			
		||||
      if (_find) {
 | 
			
		||||
        return _find[1]?.style || {}
 | 
			
		||||
      }
 | 
			
		||||
      return {}
 | 
			
		||||
    },
 | 
			
		||||
    getChoiceValueIcon(col, colValue) {
 | 
			
		||||
      const _find = col.choice_value.find((item) => String(item[0]) === String(colValue))
 | 
			
		||||
      if (_find) {
 | 
			
		||||
        return _find[1]?.icon || {}
 | 
			
		||||
      }
 | 
			
		||||
      return {}
 | 
			
		||||
    },
 | 
			
		||||
    getName(name) {
 | 
			
		||||
      return name ?? ''
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
<template>
 | 
			
		||||
  <span :id="`ci-detail-attr-${attr.name}`">
 | 
			
		||||
    <span v-if="!isEdit || attr.value_type === '6'">
 | 
			
		||||
      <PasswordField
 | 
			
		||||
        :style="{ display: 'inline-block' }"
 | 
			
		||||
        v-if="attr.is_password && ci[attr.name]"
 | 
			
		||||
        :ci_id="ci._id"
 | 
			
		||||
        :attr_id="attr.id"
 | 
			
		||||
      ></PasswordField>
 | 
			
		||||
      <template v-else-if="attr.value_type === '6'">{{ JSON.stringify(ci[attr.name] || {}) }}</template>
 | 
			
		||||
      <template v-else-if="attr.is_choice">
 | 
			
		||||
        <template v-if="attr.is_list">
 | 
			
		||||
          <span
 | 
			
		||||
            v-for="value in ci[attr.name]"
 | 
			
		||||
            :key="value"
 | 
			
		||||
            :style="{
 | 
			
		||||
              borderRadius: '4px',
 | 
			
		||||
              padding: '1px 5px',
 | 
			
		||||
              margin: '2px',
 | 
			
		||||
              ...getChoiceValueStyle(attr, value),
 | 
			
		||||
              display: 'inline-flex',
 | 
			
		||||
              alignItems: 'center',
 | 
			
		||||
            }"
 | 
			
		||||
          >
 | 
			
		||||
            <img
 | 
			
		||||
              v-if="getChoiceValueIcon(attr, value).id && getChoiceValueIcon(attr, value).url"
 | 
			
		||||
              :src="`/api/common-setting/v1/file/${getChoiceValueIcon(attr, value).url}`"
 | 
			
		||||
              :style="{ maxHeight: '13px', maxWidth: '13px', marginRight: '5px' }"
 | 
			
		||||
            />
 | 
			
		||||
            <ops-icon
 | 
			
		||||
              v-else
 | 
			
		||||
              :style="{ color: getChoiceValueIcon(attr, value).color, marginRight: '5px' }"
 | 
			
		||||
              :type="getChoiceValueIcon(attr, value).name"
 | 
			
		||||
            />
 | 
			
		||||
            {{ value }}</span
 | 
			
		||||
          >
 | 
			
		||||
        </template>
 | 
			
		||||
        <span
 | 
			
		||||
          v-else
 | 
			
		||||
          :style="{
 | 
			
		||||
            borderRadius: '4px',
 | 
			
		||||
            padding: '1px 5px',
 | 
			
		||||
            margin: '2px 0',
 | 
			
		||||
            ...getChoiceValueStyle(attr, ci[attr.name]),
 | 
			
		||||
            display: 'inline-flex',
 | 
			
		||||
            alignItems: 'center',
 | 
			
		||||
          }"
 | 
			
		||||
        >
 | 
			
		||||
          <img
 | 
			
		||||
            v-if="getChoiceValueIcon(attr, ci[attr.name]).id && getChoiceValueIcon(attr, ci[attr.name]).url"
 | 
			
		||||
            :src="`/api/common-setting/v1/file/${getChoiceValueIcon(attr, ci[attr.name]).url}`"
 | 
			
		||||
            :style="{ maxHeight: '13px', maxWidth: '13px', marginRight: '5px' }"
 | 
			
		||||
          />
 | 
			
		||||
          <ops-icon
 | 
			
		||||
            v-else
 | 
			
		||||
            :style="{ color: getChoiceValueIcon(attr, ci[attr.name]).color, marginRight: '5px' }"
 | 
			
		||||
            :type="getChoiceValueIcon(attr, ci[attr.name]).name"
 | 
			
		||||
          />
 | 
			
		||||
          {{ ci[attr.name] }}
 | 
			
		||||
        </span>
 | 
			
		||||
      </template>
 | 
			
		||||
      <template v-else>{{ getName(ci[attr.name]) }}</template>
 | 
			
		||||
    </span>
 | 
			
		||||
    <template v-else>
 | 
			
		||||
      <a-form :form="form">
 | 
			
		||||
        <a-form-item label="" :colon="false">
 | 
			
		||||
          <a-select
 | 
			
		||||
            :style="{ width: '100%' }"
 | 
			
		||||
            v-decorator="[
 | 
			
		||||
              attr.name,
 | 
			
		||||
              {
 | 
			
		||||
                rules: [{ required: attr.is_required }],
 | 
			
		||||
              },
 | 
			
		||||
            ]"
 | 
			
		||||
            placeholder="请选择"
 | 
			
		||||
            v-if="attr.is_choice"
 | 
			
		||||
            :mode="attr.is_list ? 'multiple' : 'default'"
 | 
			
		||||
            :multiple="attr.is_list"
 | 
			
		||||
            showSearch
 | 
			
		||||
            allowClear
 | 
			
		||||
            size="small"
 | 
			
		||||
            :getPopupContainer="(trigger) => trigger.parentElement"
 | 
			
		||||
          >
 | 
			
		||||
            <a-select-option
 | 
			
		||||
              :value="choice[0]"
 | 
			
		||||
              :key="'New_' + attr.name + choice_idx"
 | 
			
		||||
              v-for="(choice, choice_idx) in attr.choice_value"
 | 
			
		||||
            >
 | 
			
		||||
              <span :style="{ ...(choice[1] ? choice[1].style : {}), display: 'inline-flex', alignItems: 'center' }">
 | 
			
		||||
                <template v-if="choice[1] && choice[1].icon && choice[1].icon.name">
 | 
			
		||||
                  <img
 | 
			
		||||
                    v-if="choice[1].icon.id && choice[1].icon.url"
 | 
			
		||||
                    :src="`/api/common-setting/v1/file/${choice[1].icon.url}`"
 | 
			
		||||
                    :style="{ maxHeight: '13px', maxWidth: '13px', marginRight: '5px' }"
 | 
			
		||||
                  />
 | 
			
		||||
                  <ops-icon
 | 
			
		||||
                    v-else
 | 
			
		||||
                    :style="{ color: choice[1].icon.color, marginRight: '5px' }"
 | 
			
		||||
                    :type="choice[1].icon.name"
 | 
			
		||||
                  />
 | 
			
		||||
                </template>
 | 
			
		||||
                {{ choice[0] }}
 | 
			
		||||
              </span>
 | 
			
		||||
            </a-select-option>
 | 
			
		||||
          </a-select>
 | 
			
		||||
          <a-input-number
 | 
			
		||||
            size="small"
 | 
			
		||||
            v-decorator="[
 | 
			
		||||
              attr.name,
 | 
			
		||||
              {
 | 
			
		||||
                rules: [{ required: attr.is_required }],
 | 
			
		||||
              },
 | 
			
		||||
            ]"
 | 
			
		||||
            style="width: 100%"
 | 
			
		||||
            v-else-if="attr.value_type === '0' || attr.value_type === '1'"
 | 
			
		||||
          />
 | 
			
		||||
          <a-date-picker
 | 
			
		||||
            size="small"
 | 
			
		||||
            v-decorator="[
 | 
			
		||||
              attr.name,
 | 
			
		||||
              {
 | 
			
		||||
                rules: [{ required: attr.is_required }],
 | 
			
		||||
              },
 | 
			
		||||
            ]"
 | 
			
		||||
            style="width: 100%"
 | 
			
		||||
            :format="attr.value_type === '4' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
 | 
			
		||||
            :valueFormat="attr.value_type === '4' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
 | 
			
		||||
            v-else-if="attr.value_type === '4' || attr.value_type === '3'"
 | 
			
		||||
            :showTime="attr.value_type === '4' ? false : { format: 'HH:mm:ss' }"
 | 
			
		||||
          />
 | 
			
		||||
          <!-- <a-input
 | 
			
		||||
            size="small"
 | 
			
		||||
            @focus="(e) => handleFocusInput(e, attr)"
 | 
			
		||||
            v-decorator="[
 | 
			
		||||
              attr.name,
 | 
			
		||||
              {
 | 
			
		||||
                validateTrigger: ['submit'],
 | 
			
		||||
                rules: [{ required: attr.is_required }],
 | 
			
		||||
              },
 | 
			
		||||
            ]"
 | 
			
		||||
            style="width: 100%"
 | 
			
		||||
            v-else-if="attr.value_type === '6'"
 | 
			
		||||
          /> -->
 | 
			
		||||
          <a-input
 | 
			
		||||
            size="small"
 | 
			
		||||
            v-decorator="[
 | 
			
		||||
              attr.name,
 | 
			
		||||
              {
 | 
			
		||||
                validateTrigger: ['submit'],
 | 
			
		||||
                rules: [{ required: attr.is_required }],
 | 
			
		||||
              },
 | 
			
		||||
            ]"
 | 
			
		||||
            style="width: 100%"
 | 
			
		||||
            v-else
 | 
			
		||||
          />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-form>
 | 
			
		||||
    </template>
 | 
			
		||||
    <a v-if="!isEdit && !attr.is_computed" @click="handleEdit" :style="{ opacity: 0 }"><a-icon type="edit"/></a>
 | 
			
		||||
    <JsonEditor ref="jsonEditor" @jsonEditorOk="jsonEditorOk" />
 | 
			
		||||
  </span>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import _ from 'lodash'
 | 
			
		||||
import moment from 'moment'
 | 
			
		||||
import { updateCI } from '@/modules/cmdb/api/ci'
 | 
			
		||||
import JsonEditor from '../../../components/JsonEditor/jsonEditor.vue'
 | 
			
		||||
import PasswordField from '../../../components/passwordField/index.vue'
 | 
			
		||||
import { getAttrPassword } from '../../../api/CITypeAttr'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'CiDetailAttrContent',
 | 
			
		||||
  components: { JsonEditor, PasswordField },
 | 
			
		||||
  props: {
 | 
			
		||||
    ci: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
    attr: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      isEdit: false,
 | 
			
		||||
      form: this.$form.createForm(this, this.attr.name),
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  mounted() {
 | 
			
		||||
    document.addEventListener('click', this.eventListener)
 | 
			
		||||
  },
 | 
			
		||||
  beforeDestroy() {
 | 
			
		||||
    document.removeEventListener('click', this.eventListener)
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    moment,
 | 
			
		||||
    eventListener(e) {
 | 
			
		||||
      const datePickerContainer = document.getElementsByClassName('ant-calendar-picker-container')
 | 
			
		||||
      if (this.isEdit && !datePickerContainer.length) {
 | 
			
		||||
        const dom = document.getElementById(`ci-detail-attr-${this.attr.name}`)
 | 
			
		||||
        e.stopPropagation()
 | 
			
		||||
        e.preventDefault()
 | 
			
		||||
        if (dom) {
 | 
			
		||||
          const isSelf = dom.contains(e.target)
 | 
			
		||||
          if (!isSelf) {
 | 
			
		||||
            this.handleCloseEdit()
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleEdit(e) {
 | 
			
		||||
      e.stopPropagation()
 | 
			
		||||
      e.preventDefault()
 | 
			
		||||
      if (this.attr.value_type === '6') {
 | 
			
		||||
        const jsonData = this.ci[this.attr.name]
 | 
			
		||||
        this.$refs.jsonEditor.open(null, null, jsonData || {})
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      this.isEdit = true
 | 
			
		||||
      this.$nextTick(async () => {
 | 
			
		||||
        if (this.attr.is_list && !this.attr.is_choice) {
 | 
			
		||||
          this.form.setFieldsValue({
 | 
			
		||||
            [`${this.attr.name}`]: this.ci[this.attr.name].join(',') || null,
 | 
			
		||||
          })
 | 
			
		||||
          return
 | 
			
		||||
        }
 | 
			
		||||
        if (this.attr.is_password) {
 | 
			
		||||
          await getAttrPassword(this.ci._id, this.attr.id).then((res) => {
 | 
			
		||||
            this.form.setFieldsValue({
 | 
			
		||||
              [`${this.attr.name}`]: res.value ?? null,
 | 
			
		||||
            })
 | 
			
		||||
          })
 | 
			
		||||
          return
 | 
			
		||||
        }
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          [`${this.attr.name}`]: this.ci[this.attr.name] ?? null,
 | 
			
		||||
        })
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    async handleCloseEdit() {
 | 
			
		||||
      const newData = this.form.getFieldValue(this.attr.name)
 | 
			
		||||
      if (!_.isEqual(this.ci[this.attr.name], newData)) {
 | 
			
		||||
        await updateCI(this.ci._id, { [`${this.attr.name}`]: newData })
 | 
			
		||||
          .then(() => {
 | 
			
		||||
            this.$message.success('更新成功!')
 | 
			
		||||
            this.$emit('updateCIByself', { [`${this.attr.name}`]: newData }, this.attr.name)
 | 
			
		||||
          })
 | 
			
		||||
          .catch(() => {
 | 
			
		||||
            this.$emit('refresh', this.attr.name)
 | 
			
		||||
          })
 | 
			
		||||
      }
 | 
			
		||||
      this.isEdit = false
 | 
			
		||||
    },
 | 
			
		||||
    // handleFocusInput(e, attr) {
 | 
			
		||||
    //   console.log('focus')
 | 
			
		||||
    //   if (this.attr.value_type === '6') {
 | 
			
		||||
    //     e.preventDefault()
 | 
			
		||||
    //     e.stopPropagation()
 | 
			
		||||
    //     // e.srcElement.blur()
 | 
			
		||||
    //     const jsonData = this.form.getFieldValue(attr.name)
 | 
			
		||||
    //     this.$refs.jsonEditor.open(null, null, jsonData ? JSON.parse(jsonData) : {})
 | 
			
		||||
    //   }
 | 
			
		||||
    // },
 | 
			
		||||
    jsonEditorOk(jsonData) {
 | 
			
		||||
      if (!_.isEqual(this.ci[this.attr.name], jsonData)) {
 | 
			
		||||
        updateCI(this.ci._id, { [`${this.attr.name}`]: jsonData })
 | 
			
		||||
          .then(() => {
 | 
			
		||||
            this.$message.success('更新成功!')
 | 
			
		||||
            this.$emit('updateCIByself', { [`${this.attr.name}`]: jsonData }, this.attr.name)
 | 
			
		||||
          })
 | 
			
		||||
          .catch(() => {
 | 
			
		||||
            this.$emit('refresh', this.attr.name)
 | 
			
		||||
          })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    getChoiceValueStyle(col, colValue) {
 | 
			
		||||
      const _find = col.choice_value.find((item) => String(item[0]) === String(colValue))
 | 
			
		||||
      if (_find) {
 | 
			
		||||
        return _find[1]?.style || {}
 | 
			
		||||
      }
 | 
			
		||||
      return {}
 | 
			
		||||
    },
 | 
			
		||||
    getChoiceValueIcon(col, colValue) {
 | 
			
		||||
      const _find = col.choice_value.find((item) => String(item[0]) === String(colValue))
 | 
			
		||||
      if (_find) {
 | 
			
		||||
        return _find[1]?.icon || {}
 | 
			
		||||
      }
 | 
			
		||||
      return {}
 | 
			
		||||
    },
 | 
			
		||||
    getName(name) {
 | 
			
		||||
      return name ?? ''
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,280 +1,274 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div class="attribute-card">
 | 
			
		||||
    <div class="attribute-card-content">
 | 
			
		||||
      <div class="attribute-card-value-type-icon handle" :style="{ ...getPropertyStyle(property) }">
 | 
			
		||||
        <ValueTypeIcon :attr="property" />
 | 
			
		||||
      </div>
 | 
			
		||||
      <div :class="{ 'attribute-card-content-inner': true, 'attribute-card-name-required': property.is_required }">
 | 
			
		||||
        <div :class="{ 'attribute-card-name': true, 'attribute-card-name-default-show': property.default_show }">
 | 
			
		||||
          {{ property.alias || property.name }}
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="attribute-card_value-type">{{ valueTypeMap[property.value_type] }}</div>
 | 
			
		||||
      </div>
 | 
			
		||||
      <div
 | 
			
		||||
        class="attribute-card-trigger"
 | 
			
		||||
        v-if="(property.value_type === '3' || property.value_type === '4') && !isStore"
 | 
			
		||||
      >
 | 
			
		||||
        <a @click="openTrigger"><ops-icon type="ops-trigger"/></a>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="attribute-card-footer">
 | 
			
		||||
      <a-popover
 | 
			
		||||
        trigger="click"
 | 
			
		||||
        :arrowPointAtCenter="true"
 | 
			
		||||
        placement="bottom"
 | 
			
		||||
        overlayClassName="attribute-card-footer-popover"
 | 
			
		||||
      >
 | 
			
		||||
        <div slot="content">
 | 
			
		||||
          <h3 :style="{ textAlign: 'center', paddingTop: '0.5em' }">
 | 
			
		||||
            <span>{{ property.alias }}({{ property.name }})</span>
 | 
			
		||||
          </h3>
 | 
			
		||||
          <a-descriptions layout="horizontal" bordered size="small" :column="2">
 | 
			
		||||
            <a-descriptions-item v-for="item in propertyList" :key="item.property" :label="item.label">
 | 
			
		||||
              <components
 | 
			
		||||
                :is="`ops_${item.property}`"
 | 
			
		||||
                v-if="property[item.property]"
 | 
			
		||||
                :style="{ width: '1em', height: '1em' }"
 | 
			
		||||
              />
 | 
			
		||||
              <ops-icon v-else :type="`ops-${item.property}-disabled`" />
 | 
			
		||||
            </a-descriptions-item>
 | 
			
		||||
            <a-descriptions-item label></a-descriptions-item>
 | 
			
		||||
          </a-descriptions>
 | 
			
		||||
        </div>
 | 
			
		||||
        <a-space :style="{ cursor: 'pointer' }">
 | 
			
		||||
          <components
 | 
			
		||||
            v-for="item in propertyList.filter((p) => property[p.property])"
 | 
			
		||||
            :key="item.property"
 | 
			
		||||
            :is="`ops_${item.property}`"
 | 
			
		||||
          />
 | 
			
		||||
        </a-space>
 | 
			
		||||
      </a-popover>
 | 
			
		||||
 | 
			
		||||
      <a-space class="attribute-card-operation">
 | 
			
		||||
        <a v-if="!isStore"><a-icon type="edit" @click="handleEdit"/></a>
 | 
			
		||||
        <a-tooltip title="所有CI触发计算">
 | 
			
		||||
          <a v-if="!isStore && property.is_computed"><a-icon type="redo" @click="handleCalcComputed"/></a>
 | 
			
		||||
        </a-tooltip>
 | 
			
		||||
        <a style="color:red;"><a-icon type="delete" @click="handleDelete"/></a>
 | 
			
		||||
      </a-space>
 | 
			
		||||
    </div>
 | 
			
		||||
    <TriggerForm ref="triggerForm" :CITypeId="CITypeId" />
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { deleteCITypeAttributesById, deleteAttributesById, calcComputedAttribute } from '@/modules/cmdb/api/CITypeAttr'
 | 
			
		||||
import ValueTypeIcon from '@/components/CMDBValueTypeMapIcon'
 | 
			
		||||
import {
 | 
			
		||||
  ops_default_show,
 | 
			
		||||
  ops_is_choice,
 | 
			
		||||
  ops_is_index,
 | 
			
		||||
  ops_is_link,
 | 
			
		||||
  ops_is_password,
 | 
			
		||||
  ops_is_sortable,
 | 
			
		||||
  ops_is_unique,
 | 
			
		||||
} from '@/core/icons'
 | 
			
		||||
import { valueTypeMap } from '../../utils/const'
 | 
			
		||||
import { getPropertyStyle } from '../../utils/helper'
 | 
			
		||||
import TriggerForm from './triggerForm.vue'
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'AttributeCard',
 | 
			
		||||
  components: {
 | 
			
		||||
    ValueTypeIcon,
 | 
			
		||||
    TriggerForm,
 | 
			
		||||
    ops_default_show,
 | 
			
		||||
    ops_is_choice,
 | 
			
		||||
    ops_is_index,
 | 
			
		||||
    ops_is_link,
 | 
			
		||||
    ops_is_password,
 | 
			
		||||
    ops_is_sortable,
 | 
			
		||||
    ops_is_unique,
 | 
			
		||||
  },
 | 
			
		||||
  props: {
 | 
			
		||||
    property: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
    CITypeId: {
 | 
			
		||||
      type: Number,
 | 
			
		||||
      default: null,
 | 
			
		||||
    },
 | 
			
		||||
    isStore: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: false,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    const propertyList = [
 | 
			
		||||
      {
 | 
			
		||||
        label: '是否唯一',
 | 
			
		||||
        property: 'is_unique',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '是否选择',
 | 
			
		||||
        property: 'is_choice',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '默认显示',
 | 
			
		||||
        property: 'default_show',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '可排序',
 | 
			
		||||
        property: 'is_sortable',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '是否索引',
 | 
			
		||||
        property: 'is_index',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '是否密码',
 | 
			
		||||
        property: 'is_password',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '是否链接',
 | 
			
		||||
        property: 'is_link',
 | 
			
		||||
      },
 | 
			
		||||
    ]
 | 
			
		||||
    return {
 | 
			
		||||
      valueTypeMap,
 | 
			
		||||
      propertyList,
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    getPropertyStyle,
 | 
			
		||||
    handleEdit() {
 | 
			
		||||
      this.$emit('edit')
 | 
			
		||||
    },
 | 
			
		||||
    handleDelete() {
 | 
			
		||||
      const that = this
 | 
			
		||||
      this.$confirm({
 | 
			
		||||
        title: '警告',
 | 
			
		||||
        content: `确认删除 【${that.property.alias || that.property.name}】?`,
 | 
			
		||||
        onOk() {
 | 
			
		||||
          if (that.isStore) {
 | 
			
		||||
            deleteAttributesById(that.property.id).then(() => {
 | 
			
		||||
              that.$message.success('删除成功!')
 | 
			
		||||
              that.$emit('ok')
 | 
			
		||||
            })
 | 
			
		||||
          } else {
 | 
			
		||||
            deleteCITypeAttributesById(that.CITypeId, { attr_id: [that.property.id] }).then(() => {
 | 
			
		||||
              that.$message.success('删除成功!')
 | 
			
		||||
              that.$emit('ok')
 | 
			
		||||
            })
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        onCancel() {},
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    openTrigger() {
 | 
			
		||||
      this.$refs.triggerForm.open(this.property)
 | 
			
		||||
    },
 | 
			
		||||
    handleCalcComputed() {
 | 
			
		||||
      const that = this
 | 
			
		||||
      this.$confirm({
 | 
			
		||||
        title: '警告',
 | 
			
		||||
        content: `确认触发所有CI的计算?`,
 | 
			
		||||
        onOk() {
 | 
			
		||||
          calcComputedAttribute(that.property.id).then(() => {
 | 
			
		||||
            that.$message.success('触发成功!')
 | 
			
		||||
          })
 | 
			
		||||
        },
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="less" scoped>
 | 
			
		||||
.attribute-card {
 | 
			
		||||
  width: 182px;
 | 
			
		||||
  height: 80px;
 | 
			
		||||
  background: #f8faff;
 | 
			
		||||
  border-radius: 5px;
 | 
			
		||||
  position: relative;
 | 
			
		||||
  margin-bottom: 16px;
 | 
			
		||||
  transition: all 0.3s;
 | 
			
		||||
  &:hover {
 | 
			
		||||
    box-shadow: 0 4px 12px #4e5ea066;
 | 
			
		||||
    .attribute-card-operation {
 | 
			
		||||
      visibility: visible !important;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  .attribute-card-content {
 | 
			
		||||
    height: 50px;
 | 
			
		||||
    display: inline-flex;
 | 
			
		||||
    align-items: center;
 | 
			
		||||
    padding: 8px;
 | 
			
		||||
    width: 100%;
 | 
			
		||||
    .attribute-card-value-type-icon {
 | 
			
		||||
      width: 32px;
 | 
			
		||||
      height: 32px;
 | 
			
		||||
      font-size: 12px;
 | 
			
		||||
      cursor: move;
 | 
			
		||||
      background: #ffffff !important;
 | 
			
		||||
      box-shadow: 0px 1px 2px rgba(47, 84, 235, 0.2);
 | 
			
		||||
      border-radius: 2px;
 | 
			
		||||
      text-align: center;
 | 
			
		||||
      line-height: 32px;
 | 
			
		||||
    }
 | 
			
		||||
    .attribute-card-content-inner {
 | 
			
		||||
      padding-left: 12px;
 | 
			
		||||
      font-weight: 400;
 | 
			
		||||
      font-size: 12px;
 | 
			
		||||
      width: 120px;
 | 
			
		||||
      position: relative;
 | 
			
		||||
      .attribute-card-name {
 | 
			
		||||
        width: 100%;
 | 
			
		||||
        color: rgba(0, 0, 0, 0.8);
 | 
			
		||||
        overflow: hidden;
 | 
			
		||||
        text-overflow: ellipsis;
 | 
			
		||||
        white-space: nowrap;
 | 
			
		||||
      }
 | 
			
		||||
      .attribute-card-name-default-show {
 | 
			
		||||
        color: #2f54eb;
 | 
			
		||||
      }
 | 
			
		||||
      .attribute-card_value-type {
 | 
			
		||||
        font-size: 10px;
 | 
			
		||||
        color: rgba(0, 0, 0, 0.35);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    .attribute-card-name-required::before {
 | 
			
		||||
      content: '*';
 | 
			
		||||
      width: 5px;
 | 
			
		||||
      color: red;
 | 
			
		||||
      position: absolute;
 | 
			
		||||
      left: 3px;
 | 
			
		||||
    }
 | 
			
		||||
    .attribute-card-trigger {
 | 
			
		||||
      position: absolute;
 | 
			
		||||
      right: 8px;
 | 
			
		||||
      top: 8px;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  .attribute-card-footer {
 | 
			
		||||
    width: 182px;
 | 
			
		||||
    height: 30px;
 | 
			
		||||
    padding: 0 8px;
 | 
			
		||||
    position: absolute;
 | 
			
		||||
    bottom: 0;
 | 
			
		||||
    left: 0;
 | 
			
		||||
    background: linear-gradient(180deg, #96abd6 0%, #ecf2ff 0.01%, #ffffff 143.33%);
 | 
			
		||||
    border-radius: 0px 0px 5px 5px;
 | 
			
		||||
    display: inline-flex;
 | 
			
		||||
    align-items: center;
 | 
			
		||||
    justify-content: space-between;
 | 
			
		||||
    .attribute-card-operation {
 | 
			
		||||
      visibility: hidden;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
<style lang="less">
 | 
			
		||||
.attribute-card-footer-popover {
 | 
			
		||||
  .ant-popover-inner-content {
 | 
			
		||||
    padding: 0;
 | 
			
		||||
  }
 | 
			
		||||
  .ant-descriptions-bordered .ant-descriptions-item-label {
 | 
			
		||||
    background-color: #f8faff;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
<template>
 | 
			
		||||
  <div class="attribute-card">
 | 
			
		||||
    <div class="attribute-card-content">
 | 
			
		||||
      <div class="attribute-card-value-type-icon handle" :style="{ ...getPropertyStyle(property) }">
 | 
			
		||||
        <ValueTypeIcon :attr="property" />
 | 
			
		||||
      </div>
 | 
			
		||||
      <div :class="{ 'attribute-card-content-inner': true, 'attribute-card-name-required': property.is_required }">
 | 
			
		||||
        <div :class="{ 'attribute-card-name': true, 'attribute-card-name-default-show': property.default_show }">
 | 
			
		||||
          {{ property.alias || property.name }}
 | 
			
		||||
        </div>
 | 
			
		||||
        <div v-if="property.is_password" class="attribute-card_value-type">密码</div>
 | 
			
		||||
        <div v-else-if="property.is_link" class="attribute-card_value-type">链接</div>
 | 
			
		||||
        <div v-else class="attribute-card_value-type">{{ valueTypeMap[property.value_type] }}</div>
 | 
			
		||||
      </div>
 | 
			
		||||
      <div
 | 
			
		||||
        class="attribute-card-trigger"
 | 
			
		||||
        v-if="(property.value_type === '3' || property.value_type === '4') && !isStore"
 | 
			
		||||
      >
 | 
			
		||||
        <a @click="openTrigger"><ops-icon type="ops-trigger"/></a>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="attribute-card-footer">
 | 
			
		||||
      <a-popover
 | 
			
		||||
        trigger="click"
 | 
			
		||||
        :arrowPointAtCenter="true"
 | 
			
		||||
        placement="bottom"
 | 
			
		||||
        overlayClassName="attribute-card-footer-popover"
 | 
			
		||||
      >
 | 
			
		||||
        <div slot="content">
 | 
			
		||||
          <h3 :style="{ textAlign: 'center', paddingTop: '0.5em' }">
 | 
			
		||||
            <span>{{ property.alias }}({{ property.name }})</span>
 | 
			
		||||
          </h3>
 | 
			
		||||
          <a-descriptions layout="horizontal" bordered size="small" :column="2">
 | 
			
		||||
            <a-descriptions-item v-for="item in propertyList" :key="item.property" :label="item.label">
 | 
			
		||||
              <components
 | 
			
		||||
                :is="`ops_${item.property}`"
 | 
			
		||||
                v-if="property[item.property]"
 | 
			
		||||
                :style="{ width: '1em', height: '1em' }"
 | 
			
		||||
              />
 | 
			
		||||
              <ops-icon v-else :type="`ops-${item.property}-disabled`" />
 | 
			
		||||
            </a-descriptions-item>
 | 
			
		||||
            <a-descriptions-item label></a-descriptions-item>
 | 
			
		||||
          </a-descriptions>
 | 
			
		||||
        </div>
 | 
			
		||||
        <a-space :style="{ cursor: 'pointer' }">
 | 
			
		||||
          <components
 | 
			
		||||
            v-for="item in propertyList.filter((p) => property[p.property])"
 | 
			
		||||
            :key="item.property"
 | 
			
		||||
            :is="`ops_${item.property}`"
 | 
			
		||||
          />
 | 
			
		||||
        </a-space>
 | 
			
		||||
      </a-popover>
 | 
			
		||||
 | 
			
		||||
      <a-space class="attribute-card-operation">
 | 
			
		||||
        <a v-if="!isStore"><a-icon type="edit" @click="handleEdit"/></a>
 | 
			
		||||
        <a-tooltip title="所有CI触发计算">
 | 
			
		||||
          <a v-if="!isStore && property.is_computed"><a-icon type="redo" @click="handleCalcComputed"/></a>
 | 
			
		||||
        </a-tooltip>
 | 
			
		||||
        <a style="color:red;"><a-icon type="delete" @click="handleDelete"/></a>
 | 
			
		||||
      </a-space>
 | 
			
		||||
    </div>
 | 
			
		||||
    <TriggerForm ref="triggerForm" :CITypeId="CITypeId" />
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { deleteCITypeAttributesById, deleteAttributesById, calcComputedAttribute } from '@/modules/cmdb/api/CITypeAttr'
 | 
			
		||||
import ValueTypeIcon from '@/components/CMDBValueTypeMapIcon'
 | 
			
		||||
import {
 | 
			
		||||
  ops_default_show,
 | 
			
		||||
  ops_is_choice,
 | 
			
		||||
  ops_is_index,
 | 
			
		||||
  ops_is_link,
 | 
			
		||||
  ops_is_password,
 | 
			
		||||
  ops_is_sortable,
 | 
			
		||||
  ops_is_unique,
 | 
			
		||||
} from '@/core/icons'
 | 
			
		||||
import { valueTypeMap } from '../../utils/const'
 | 
			
		||||
import { getPropertyStyle } from '../../utils/helper'
 | 
			
		||||
import TriggerForm from './triggerForm.vue'
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'AttributeCard',
 | 
			
		||||
  components: {
 | 
			
		||||
    ValueTypeIcon,
 | 
			
		||||
    TriggerForm,
 | 
			
		||||
    ops_default_show,
 | 
			
		||||
    ops_is_choice,
 | 
			
		||||
    ops_is_index,
 | 
			
		||||
    ops_is_link,
 | 
			
		||||
    ops_is_password,
 | 
			
		||||
    ops_is_sortable,
 | 
			
		||||
    ops_is_unique,
 | 
			
		||||
  },
 | 
			
		||||
  props: {
 | 
			
		||||
    property: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
    CITypeId: {
 | 
			
		||||
      type: Number,
 | 
			
		||||
      default: null,
 | 
			
		||||
    },
 | 
			
		||||
    isStore: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: false,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    const propertyList = [
 | 
			
		||||
      {
 | 
			
		||||
        label: '是否唯一',
 | 
			
		||||
        property: 'is_unique',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '是否选择',
 | 
			
		||||
        property: 'is_choice',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '默认显示',
 | 
			
		||||
        property: 'default_show',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '可排序',
 | 
			
		||||
        property: 'is_sortable',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        label: '是否索引',
 | 
			
		||||
        property: 'is_index',
 | 
			
		||||
      },
 | 
			
		||||
    ]
 | 
			
		||||
    return {
 | 
			
		||||
      valueTypeMap,
 | 
			
		||||
      propertyList,
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    getPropertyStyle,
 | 
			
		||||
    handleEdit() {
 | 
			
		||||
      this.$emit('edit')
 | 
			
		||||
    },
 | 
			
		||||
    handleDelete() {
 | 
			
		||||
      const that = this
 | 
			
		||||
      this.$confirm({
 | 
			
		||||
        title: '警告',
 | 
			
		||||
        content: `确认删除 【${that.property.alias || that.property.name}】?`,
 | 
			
		||||
        onOk() {
 | 
			
		||||
          if (that.isStore) {
 | 
			
		||||
            deleteAttributesById(that.property.id).then(() => {
 | 
			
		||||
              that.$message.success('删除成功!')
 | 
			
		||||
              that.$emit('ok')
 | 
			
		||||
            })
 | 
			
		||||
          } else {
 | 
			
		||||
            deleteCITypeAttributesById(that.CITypeId, { attr_id: [that.property.id] }).then(() => {
 | 
			
		||||
              that.$message.success('删除成功!')
 | 
			
		||||
              that.$emit('ok')
 | 
			
		||||
            })
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        onCancel() {},
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    openTrigger() {
 | 
			
		||||
      this.$refs.triggerForm.open(this.property)
 | 
			
		||||
    },
 | 
			
		||||
    handleCalcComputed() {
 | 
			
		||||
      const that = this
 | 
			
		||||
      this.$confirm({
 | 
			
		||||
        title: '警告',
 | 
			
		||||
        content: `确认触发所有CI的计算?`,
 | 
			
		||||
        onOk() {
 | 
			
		||||
          calcComputedAttribute(that.property.id).then(() => {
 | 
			
		||||
            that.$message.success('触发成功!')
 | 
			
		||||
          })
 | 
			
		||||
        },
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="less" scoped>
 | 
			
		||||
.attribute-card {
 | 
			
		||||
  width: 182px;
 | 
			
		||||
  height: 80px;
 | 
			
		||||
  background: #f8faff;
 | 
			
		||||
  border-radius: 5px;
 | 
			
		||||
  position: relative;
 | 
			
		||||
  margin-bottom: 16px;
 | 
			
		||||
  transition: all 0.3s;
 | 
			
		||||
  &:hover {
 | 
			
		||||
    box-shadow: 0 4px 12px #4e5ea066;
 | 
			
		||||
    .attribute-card-operation {
 | 
			
		||||
      visibility: visible !important;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  .attribute-card-content {
 | 
			
		||||
    height: 50px;
 | 
			
		||||
    display: inline-flex;
 | 
			
		||||
    align-items: center;
 | 
			
		||||
    padding: 8px;
 | 
			
		||||
    width: 100%;
 | 
			
		||||
    .attribute-card-value-type-icon {
 | 
			
		||||
      width: 32px;
 | 
			
		||||
      height: 32px;
 | 
			
		||||
      font-size: 12px;
 | 
			
		||||
      cursor: move;
 | 
			
		||||
      background: #ffffff !important;
 | 
			
		||||
      box-shadow: 0px 1px 2px rgba(47, 84, 235, 0.2);
 | 
			
		||||
      border-radius: 2px;
 | 
			
		||||
      text-align: center;
 | 
			
		||||
      line-height: 32px;
 | 
			
		||||
    }
 | 
			
		||||
    .attribute-card-content-inner {
 | 
			
		||||
      padding-left: 12px;
 | 
			
		||||
      font-weight: 400;
 | 
			
		||||
      font-size: 12px;
 | 
			
		||||
      width: 120px;
 | 
			
		||||
      position: relative;
 | 
			
		||||
      .attribute-card-name {
 | 
			
		||||
        width: 100%;
 | 
			
		||||
        color: rgba(0, 0, 0, 0.8);
 | 
			
		||||
        overflow: hidden;
 | 
			
		||||
        text-overflow: ellipsis;
 | 
			
		||||
        white-space: nowrap;
 | 
			
		||||
      }
 | 
			
		||||
      .attribute-card-name-default-show {
 | 
			
		||||
        color: #2f54eb;
 | 
			
		||||
      }
 | 
			
		||||
      .attribute-card_value-type {
 | 
			
		||||
        font-size: 10px;
 | 
			
		||||
        color: rgba(0, 0, 0, 0.35);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    .attribute-card-name-required::before {
 | 
			
		||||
      content: '*';
 | 
			
		||||
      width: 5px;
 | 
			
		||||
      color: red;
 | 
			
		||||
      position: absolute;
 | 
			
		||||
      left: 3px;
 | 
			
		||||
    }
 | 
			
		||||
    .attribute-card-trigger {
 | 
			
		||||
      position: absolute;
 | 
			
		||||
      right: 8px;
 | 
			
		||||
      top: 8px;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  .attribute-card-footer {
 | 
			
		||||
    width: 182px;
 | 
			
		||||
    height: 30px;
 | 
			
		||||
    padding: 0 8px;
 | 
			
		||||
    position: absolute;
 | 
			
		||||
    bottom: 0;
 | 
			
		||||
    left: 0;
 | 
			
		||||
    background: linear-gradient(180deg, #96abd6 0%, #ecf2ff 0.01%, #ffffff 143.33%);
 | 
			
		||||
    border-radius: 0px 0px 5px 5px;
 | 
			
		||||
    display: inline-flex;
 | 
			
		||||
    align-items: center;
 | 
			
		||||
    justify-content: space-between;
 | 
			
		||||
    .attribute-card-operation {
 | 
			
		||||
      visibility: hidden;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
<style lang="less">
 | 
			
		||||
.attribute-card-footer-popover {
 | 
			
		||||
  .ant-popover-inner-content {
 | 
			
		||||
    padding: 0;
 | 
			
		||||
  }
 | 
			
		||||
  .ant-descriptions-bordered .ant-descriptions-item-label {
 | 
			
		||||
    background-color: #f8faff;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
 
 | 
			
		||||
@@ -84,7 +84,12 @@
 | 
			
		||||
            </a-input-number>
 | 
			
		||||
            <a-input
 | 
			
		||||
              style="width: 100%"
 | 
			
		||||
              v-else-if="currentValueType === '2' || currentValueType === '5'"
 | 
			
		||||
              v-else-if="
 | 
			
		||||
                currentValueType === '2' ||
 | 
			
		||||
                  currentValueType === '5' ||
 | 
			
		||||
                  currentValueType === '7' ||
 | 
			
		||||
                  currentValueType === '8'
 | 
			
		||||
              "
 | 
			
		||||
              v-decorator="['default_value', { rules: [{ required: false }] }]"
 | 
			
		||||
            >
 | 
			
		||||
            </a-input>
 | 
			
		||||
@@ -148,13 +153,13 @@
 | 
			
		||||
          label="必须"
 | 
			
		||||
        >
 | 
			
		||||
          <a-switch
 | 
			
		||||
            @change="onChange"
 | 
			
		||||
            @change="(checked) => onChange(checked, 'is_required')"
 | 
			
		||||
            name="is_required"
 | 
			
		||||
            v-decorator="['is_required', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
          />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
      <a-col :span="6" v-if="currentValueType !== '6'">
 | 
			
		||||
      <a-col :span="6" v-if="currentValueType !== '6' && currentValueType !== '7'">
 | 
			
		||||
        <a-form-item :label-col="{ span: 8 }" :wrapper-col="horizontalFormItemLayout.wrapperCol" label="唯一">
 | 
			
		||||
          <a-switch
 | 
			
		||||
            :disabled="isShowComputedArea"
 | 
			
		||||
@@ -228,7 +233,7 @@
 | 
			
		||||
          />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
      <a-col :span="6" v-if="currentValueType !== '6'">
 | 
			
		||||
      <a-col :span="6" v-if="currentValueType !== '6' && currentValueType !== '7'">
 | 
			
		||||
        <a-form-item
 | 
			
		||||
          :label-col="currentValueType === '2' ? horizontalFormItemLayout.labelCol : { span: 8 }"
 | 
			
		||||
          :wrapper-col="horizontalFormItemLayout.wrapperCol"
 | 
			
		||||
@@ -236,14 +241,14 @@
 | 
			
		||||
        >
 | 
			
		||||
          <a-switch
 | 
			
		||||
            :disabled="isShowComputedArea"
 | 
			
		||||
            @change="onChange"
 | 
			
		||||
            @change="(checked) => onChange(checked, 'is_sortable')"
 | 
			
		||||
            name="is_sortable"
 | 
			
		||||
            v-decorator="['is_sortable', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
          />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
 | 
			
		||||
      <a-col :span="6" v-if="currentValueType !== '6'">
 | 
			
		||||
      <a-col :span="6" v-if="currentValueType !== '6' && currentValueType !== '7'">
 | 
			
		||||
        <a-form-item
 | 
			
		||||
          :label-col="currentValueType === '2' ? { span: 8 } : horizontalFormItemLayout.labelCol"
 | 
			
		||||
          :wrapper-col="horizontalFormItemLayout.wrapperCol"
 | 
			
		||||
@@ -275,31 +280,6 @@
 | 
			
		||||
          />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
      <a-col :span="6" v-if="currentValueType === '2'">
 | 
			
		||||
        <a-form-item
 | 
			
		||||
          :label-col="horizontalFormItemLayout.labelCol"
 | 
			
		||||
          :wrapper-col="horizontalFormItemLayout.wrapperCol"
 | 
			
		||||
          label="密码"
 | 
			
		||||
        >
 | 
			
		||||
          <a-switch
 | 
			
		||||
            :disabled="isShowComputedArea"
 | 
			
		||||
            @change="(checked) => onChange(checked, 'is_password')"
 | 
			
		||||
            name="is_password"
 | 
			
		||||
            v-decorator="['is_password', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
          />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
      <a-col :span="6" v-if="currentValueType === '2'">
 | 
			
		||||
        <a-form-item :label-col="{ span: 8 }" :wrapper-col="horizontalFormItemLayout.wrapperCol" label="链接">
 | 
			
		||||
          <a-switch
 | 
			
		||||
            :disabled="isShowComputedArea"
 | 
			
		||||
            @change="(checked) => onChange(checked, 'is_link')"
 | 
			
		||||
            name="is_link"
 | 
			
		||||
            v-decorator="['is_link', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
          />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
 | 
			
		||||
      <a-divider style="font-size:14px;margin-top:6px;">高级设置</a-divider>
 | 
			
		||||
      <a-row>
 | 
			
		||||
        <a-col :span="24">
 | 
			
		||||
@@ -307,12 +287,17 @@
 | 
			
		||||
            <FontArea ref="fontArea" />
 | 
			
		||||
          </a-form-item>
 | 
			
		||||
        </a-col>
 | 
			
		||||
        <a-col :span="24" v-if="currentValueType !== '6'">
 | 
			
		||||
        <a-col :span="24" v-if="!['6', '7'].includes(currentValueType)">
 | 
			
		||||
          <a-form-item :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }" label="预定义值">
 | 
			
		||||
            <PreValueArea v-if="drawerVisible" ref="preValueArea" :disabled="isShowComputedArea" />
 | 
			
		||||
            <PreValueArea
 | 
			
		||||
              v-if="drawerVisible"
 | 
			
		||||
              :canDefineScript="canDefineScript"
 | 
			
		||||
              ref="preValueArea"
 | 
			
		||||
              :disabled="isShowComputedArea"
 | 
			
		||||
            />
 | 
			
		||||
          </a-form-item>
 | 
			
		||||
        </a-col>
 | 
			
		||||
        <a-col :span="24" v-if="currentValueType !== '6'">
 | 
			
		||||
        <a-col :span="24" v-if="!['6', '7'].includes(currentValueType)">
 | 
			
		||||
          <a-form-item :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
 | 
			
		||||
            <template slot="label">
 | 
			
		||||
              <span
 | 
			
		||||
@@ -340,7 +325,7 @@
 | 
			
		||||
            <a-switch
 | 
			
		||||
              :disabled="!canDefineComputed"
 | 
			
		||||
              @change="(checked) => onChange(checked, 'is_computed')"
 | 
			
		||||
              name="is_password"
 | 
			
		||||
              name="is_computed"
 | 
			
		||||
              v-decorator="['is_computed', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
            />
 | 
			
		||||
            <ComputedArea
 | 
			
		||||
@@ -366,6 +351,7 @@
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import _ from 'lodash'
 | 
			
		||||
import moment from 'moment'
 | 
			
		||||
import vueJsonEditor from 'vue-json-editor'
 | 
			
		||||
import {
 | 
			
		||||
@@ -434,6 +420,9 @@ export default {
 | 
			
		||||
        wrapperCol: { span: 4 },
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    canDefineScript() {
 | 
			
		||||
      return this.canDefineComputed
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  mounted() {},
 | 
			
		||||
  methods: {
 | 
			
		||||
@@ -463,28 +452,30 @@ export default {
 | 
			
		||||
          })
 | 
			
		||||
          if (this.currentValueType === '2') {
 | 
			
		||||
            this.form.setFieldsValue({
 | 
			
		||||
              is_password: false,
 | 
			
		||||
              is_link: false,
 | 
			
		||||
              is_index: true,
 | 
			
		||||
            })
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if (checked && property === 'is_password') {
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          is_link: false,
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (checked && property === 'is_link') {
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          is_password: false,
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (property === 'is_list') {
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          default_value: checked ? [] : '',
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (checked && property === 'is_sortable') {
 | 
			
		||||
        this.$message.warning('选中排序,则必须也要选中!')
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          is_required: true,
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (!checked && property === 'is_required' && this.form.getFieldValue('is_sortable')) {
 | 
			
		||||
        this.$message.warning('选中排序,则必须也要选中!')
 | 
			
		||||
        this.$nextTick(() => {
 | 
			
		||||
          this.form.setFieldsValue({
 | 
			
		||||
            is_required: true,
 | 
			
		||||
          })
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    async handleEdit(record, attributes) {
 | 
			
		||||
@@ -494,90 +485,91 @@ export default {
 | 
			
		||||
      } catch {
 | 
			
		||||
        this.canDefineComputed = false
 | 
			
		||||
      }
 | 
			
		||||
      const _record = _.cloneDeep(record)
 | 
			
		||||
      if (_record.is_password) {
 | 
			
		||||
        _record.value_type = '7'
 | 
			
		||||
      }
 | 
			
		||||
      if (_record.is_link) {
 | 
			
		||||
        _record.value_type = '8'
 | 
			
		||||
      }
 | 
			
		||||
      this.drawerTitle = '编辑属性'
 | 
			
		||||
      this.drawerVisible = true
 | 
			
		||||
      this.record = record
 | 
			
		||||
      this.currentValueType = record.value_type
 | 
			
		||||
      this.record = _record
 | 
			
		||||
      this.currentValueType = _record.value_type
 | 
			
		||||
      this.$nextTick(() => {
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          id: record.id,
 | 
			
		||||
          alias: record.alias,
 | 
			
		||||
          name: record.name,
 | 
			
		||||
          value_type: record.value_type,
 | 
			
		||||
          is_required: record.is_required,
 | 
			
		||||
          default_show: record.default_show,
 | 
			
		||||
          id: _record.id,
 | 
			
		||||
          alias: _record.alias,
 | 
			
		||||
          name: _record.name,
 | 
			
		||||
          value_type: _record.value_type,
 | 
			
		||||
          is_required: _record.is_required,
 | 
			
		||||
          default_show: _record.default_show,
 | 
			
		||||
        })
 | 
			
		||||
        if (record.value_type !== '6') {
 | 
			
		||||
        if (!['6', '7'].includes(_record.value_type)) {
 | 
			
		||||
          this.form.setFieldsValue({
 | 
			
		||||
            is_list: record.is_list,
 | 
			
		||||
            is_unique: record.is_unique,
 | 
			
		||||
            is_index: record.is_index,
 | 
			
		||||
            is_sortable: record.is_sortable,
 | 
			
		||||
            is_computed: record.is_computed,
 | 
			
		||||
            is_list: _record.is_list,
 | 
			
		||||
            is_unique: _record.is_unique,
 | 
			
		||||
            is_index: _record.is_index,
 | 
			
		||||
            is_sortable: _record.is_sortable,
 | 
			
		||||
            is_computed: _record.is_computed,
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
        if (record.value_type === '2') {
 | 
			
		||||
          this.form.setFieldsValue({
 | 
			
		||||
            is_password: record.is_password,
 | 
			
		||||
            is_link: record.is_link,
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
        console.log(record)
 | 
			
		||||
        if (record.default) {
 | 
			
		||||
        console.log(_record)
 | 
			
		||||
        if (_record.default) {
 | 
			
		||||
          this.$nextTick(() => {
 | 
			
		||||
            if (record.value_type === '0') {
 | 
			
		||||
            if (_record.value_type === '0') {
 | 
			
		||||
              this.form.setFieldsValue({
 | 
			
		||||
                default_value: record.default.default ? [record.default.default] : [],
 | 
			
		||||
                default_value: _record.default.default ? [_record.default.default] : [],
 | 
			
		||||
              })
 | 
			
		||||
            } else if (record.value_type === '6') {
 | 
			
		||||
              this.default_value_json = record?.default?.default || null
 | 
			
		||||
            } else if (record.value_type === '3' || record.value_type === '4') {
 | 
			
		||||
              if (record?.default?.default === '$created_at' || record?.default?.default === '$updated_at') {
 | 
			
		||||
                this.defaultForDatetime = record.default.default
 | 
			
		||||
            } else if (_record.value_type === '6') {
 | 
			
		||||
              this.default_value_json = _record?.default?.default || null
 | 
			
		||||
            } else if (_record.value_type === '3' || _record.value_type === '4') {
 | 
			
		||||
              if (_record?.default?.default === '$created_at' || _record?.default?.default === '$updated_at') {
 | 
			
		||||
                this.defaultForDatetime = _record.default.default
 | 
			
		||||
                this.form.setFieldsValue({
 | 
			
		||||
                  default_value: record?.default?.default,
 | 
			
		||||
                  default_value: _record?.default?.default,
 | 
			
		||||
                })
 | 
			
		||||
              } else {
 | 
			
		||||
                this.defaultForDatetime = '$custom_time'
 | 
			
		||||
                this.form.setFieldsValue({
 | 
			
		||||
                  default_value: record.default && record.default.default ? moment(record.default.default) : null,
 | 
			
		||||
                  default_value: _record.default && _record.default.default ? moment(_record.default.default) : null,
 | 
			
		||||
                })
 | 
			
		||||
              }
 | 
			
		||||
            } else {
 | 
			
		||||
              this.$nextTick(() => {
 | 
			
		||||
                this.form.setFieldsValue({
 | 
			
		||||
                  default_value: record.default && record.default.default ? record.default.default : null,
 | 
			
		||||
                  default_value: _record.default && _record.default.default ? _record.default.default : null,
 | 
			
		||||
                })
 | 
			
		||||
              })
 | 
			
		||||
            }
 | 
			
		||||
          })
 | 
			
		||||
        } else {
 | 
			
		||||
          this.default_value_json = {}
 | 
			
		||||
          if (record.value_type === '0') {
 | 
			
		||||
          if (_record.value_type === '0') {
 | 
			
		||||
            this.form.setFieldsValue({
 | 
			
		||||
              default_value: [],
 | 
			
		||||
            })
 | 
			
		||||
          } else if (record.value_type !== '6') {
 | 
			
		||||
          } else if (_record.value_type !== '6') {
 | 
			
		||||
            this.form.setFieldsValue({
 | 
			
		||||
              default_value: null,
 | 
			
		||||
            })
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        this.isShowComputedArea = record.is_computed
 | 
			
		||||
        if (record.is_computed) {
 | 
			
		||||
        this.isShowComputedArea = _record.is_computed
 | 
			
		||||
        if (_record.is_computed) {
 | 
			
		||||
          this.$nextTick(() => {
 | 
			
		||||
            this.$refs.computedArea.setData({
 | 
			
		||||
              compute_expr: record.compute_expr,
 | 
			
		||||
              compute_script: record.compute_script,
 | 
			
		||||
              compute_expr: _record.compute_expr,
 | 
			
		||||
              compute_script: _record.compute_script,
 | 
			
		||||
            })
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
        const _find = attributes.find((item) => item.id === record.id)
 | 
			
		||||
        if (record.value_type !== '6') {
 | 
			
		||||
        const _find = attributes.find((item) => item.id === _record.id)
 | 
			
		||||
        if (!['6', '7'].includes(_record.value_type)) {
 | 
			
		||||
          this.$refs.preValueArea.setData({
 | 
			
		||||
            choice_value: (_find || {}).choice_value || [],
 | 
			
		||||
            choice_web_hook: record.choice_web_hook,
 | 
			
		||||
            choice_other: record.choice_other || undefined,
 | 
			
		||||
            choice_web_hook: _record.choice_web_hook,
 | 
			
		||||
            choice_other: _record.choice_other || undefined,
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
        this.$refs.fontArea.setData({
 | 
			
		||||
@@ -633,13 +625,20 @@ export default {
 | 
			
		||||
            values = { ...values, ...computedAreaData }
 | 
			
		||||
          } else {
 | 
			
		||||
            // 如果是非计算属性,就看看有没有预定义值
 | 
			
		||||
            if (values.value_type !== '6') {
 | 
			
		||||
            if (!['6', '7'].includes(values.value_type)) {
 | 
			
		||||
              const preValueAreaData = this.$refs.preValueArea.getData()
 | 
			
		||||
              values = { ...values, ...preValueAreaData }
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          const fontOptions = this.$refs.fontArea.getData()
 | 
			
		||||
          if (values.value_type === '7') {
 | 
			
		||||
            values.value_type = '2'
 | 
			
		||||
            values.is_password = true
 | 
			
		||||
          }
 | 
			
		||||
          if (values.value_type === '8') {
 | 
			
		||||
            values.value_type = '2'
 | 
			
		||||
            values.is_link = true
 | 
			
		||||
          }
 | 
			
		||||
          if (values.id) {
 | 
			
		||||
            await this.updateAttribute(values.id, { ...values, option: { fontOptions } }, isCalcComputed)
 | 
			
		||||
          } else {
 | 
			
		||||
@@ -660,7 +659,6 @@ export default {
 | 
			
		||||
    handleOk() {
 | 
			
		||||
      this.$emit('ok')
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    handleChangeValueType(value) {
 | 
			
		||||
      this.currentValueType = value
 | 
			
		||||
      this.$nextTick(() => {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,14 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <a-form :form="form" class="create-new-attribute">
 | 
			
		||||
  <a-form
 | 
			
		||||
    :form="form"
 | 
			
		||||
    class="create-new-attribute"
 | 
			
		||||
    :label-col="formItemLayout.labelCol"
 | 
			
		||||
    :wrapper-col="formItemLayout.wrapperCol"
 | 
			
		||||
  >
 | 
			
		||||
    <a-divider style="font-size:14px;margin-top:6px;">基础设置</a-divider>
 | 
			
		||||
    <a-row>
 | 
			
		||||
      <a-col :span="12">
 | 
			
		||||
        <a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="属性名(英文)">
 | 
			
		||||
        <a-form-item label="属性名(英文)">
 | 
			
		||||
          <a-input
 | 
			
		||||
            name="name"
 | 
			
		||||
            placeholder="英文"
 | 
			
		||||
@@ -24,28 +29,33 @@
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
      <a-col :span="12">
 | 
			
		||||
        <a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="别名">
 | 
			
		||||
        <a-form-item label="别名">
 | 
			
		||||
          <a-input name="alias" v-decorator="['alias', { rules: [] }]" />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
    </a-row>
 | 
			
		||||
    <a-row>
 | 
			
		||||
      <a-col :span="12">
 | 
			
		||||
        <a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="数据类型">
 | 
			
		||||
        <a-form-item label="数据类型">
 | 
			
		||||
          <a-select
 | 
			
		||||
            name="value_type"
 | 
			
		||||
            style="width: 100%"
 | 
			
		||||
            v-decorator="['value_type', { rules: [{ required: true }], initialValue: '2' }]"
 | 
			
		||||
            @change="handleChangeValueType"
 | 
			
		||||
          >
 | 
			
		||||
            <a-select-option :value="key" :key="key" v-for="(value, key) in valueTypeMap">{{ value }}</a-select-option>
 | 
			
		||||
            <a-select-option :value="key" :key="key" v-for="(value, key) in valueTypeMap">
 | 
			
		||||
              {{ value }}
 | 
			
		||||
              <span class="value-type-des" v-if="key === '3'">yyyy-mm-dd HH:MM:SS</span>
 | 
			
		||||
              <span class="value-type-des" v-if="key === '4'">yyyy-mm-dd</span>
 | 
			
		||||
              <span class="value-type-des" v-if="key === '5'">HH:MM:SS</span>
 | 
			
		||||
            </a-select-option>
 | 
			
		||||
          </a-select>
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
      <a-col :span="currentValueType === '6' ? 24 : 12">
 | 
			
		||||
        <a-form-item
 | 
			
		||||
          :label-col="{ span: currentValueType === '6' ? 4 : 8 }"
 | 
			
		||||
          :wrapper-col="{ span: currentValueType === '6' ? 18 : 12 }"
 | 
			
		||||
          :wrapper-col="{ span: currentValueType === '6' ? 18 : 15 }"
 | 
			
		||||
          label="默认值"
 | 
			
		||||
        >
 | 
			
		||||
          <template>
 | 
			
		||||
@@ -74,7 +84,12 @@
 | 
			
		||||
            </a-select>
 | 
			
		||||
            <a-input
 | 
			
		||||
              style="width: 100%"
 | 
			
		||||
              v-else-if="currentValueType === '2' || currentValueType === '5'"
 | 
			
		||||
              v-else-if="
 | 
			
		||||
                currentValueType === '2' ||
 | 
			
		||||
                  currentValueType === '5' ||
 | 
			
		||||
                  currentValueType === '7' ||
 | 
			
		||||
                  currentValueType === '8'
 | 
			
		||||
              "
 | 
			
		||||
              v-decorator="['default_value', { rules: [{ required: false }] }]"
 | 
			
		||||
            >
 | 
			
		||||
            </a-input>
 | 
			
		||||
@@ -140,13 +155,13 @@
 | 
			
		||||
        label="必须"
 | 
			
		||||
      >
 | 
			
		||||
        <a-switch
 | 
			
		||||
          @change="onChange"
 | 
			
		||||
          @change="(checked) => onChange(checked, 'is_required')"
 | 
			
		||||
          name="is_required"
 | 
			
		||||
          v-decorator="['is_required', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
        />
 | 
			
		||||
      </a-form-item>
 | 
			
		||||
    </a-col>
 | 
			
		||||
    <a-col :span="6" v-if="currentValueType !== '6'">
 | 
			
		||||
    <a-col :span="6" v-if="currentValueType !== '6' && currentValueType !== '7'">
 | 
			
		||||
      <a-form-item :label-col="{ span: 8 }" :wrapper-col="horizontalFormItemLayout.wrapperCol" label="唯一">
 | 
			
		||||
        <a-switch
 | 
			
		||||
          :disabled="isShowComputedArea"
 | 
			
		||||
@@ -216,7 +231,7 @@
 | 
			
		||||
        />
 | 
			
		||||
      </a-form-item>
 | 
			
		||||
    </a-col>
 | 
			
		||||
    <a-col :span="6" v-if="currentValueType !== '6'">
 | 
			
		||||
    <a-col :span="6" v-if="currentValueType !== '6' && currentValueType !== '7'">
 | 
			
		||||
      <a-form-item
 | 
			
		||||
        :label-col="currentValueType === '2' ? horizontalFormItemLayout.labelCol : { span: 8 }"
 | 
			
		||||
        :wrapper-col="horizontalFormItemLayout.wrapperCol"
 | 
			
		||||
@@ -224,14 +239,14 @@
 | 
			
		||||
      >
 | 
			
		||||
        <a-switch
 | 
			
		||||
          :disabled="isShowComputedArea"
 | 
			
		||||
          @change="onChange"
 | 
			
		||||
          @change="(checked) => onChange(checked, 'is_sortable')"
 | 
			
		||||
          name="is_sortable"
 | 
			
		||||
          v-decorator="['is_sortable', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
        />
 | 
			
		||||
      </a-form-item>
 | 
			
		||||
    </a-col>
 | 
			
		||||
 | 
			
		||||
    <a-col :span="6" v-if="currentValueType !== '6'">
 | 
			
		||||
    <a-col :span="6" v-if="currentValueType !== '6' && currentValueType !== '7'">
 | 
			
		||||
      <a-form-item
 | 
			
		||||
        :label-col="currentValueType === '2' ? { span: 8 } : horizontalFormItemLayout.labelCol"
 | 
			
		||||
        :wrapper-col="horizontalFormItemLayout.wrapperCol"
 | 
			
		||||
@@ -263,30 +278,6 @@
 | 
			
		||||
        />
 | 
			
		||||
      </a-form-item>
 | 
			
		||||
    </a-col>
 | 
			
		||||
    <a-col :span="6" v-if="currentValueType === '2'">
 | 
			
		||||
      <a-form-item
 | 
			
		||||
        :label-col="horizontalFormItemLayout.labelCol"
 | 
			
		||||
        :wrapper-col="horizontalFormItemLayout.wrapperCol"
 | 
			
		||||
        label="密码"
 | 
			
		||||
      >
 | 
			
		||||
        <a-switch
 | 
			
		||||
          :disabled="isShowComputedArea"
 | 
			
		||||
          @change="(checked) => onChange(checked, 'is_password')"
 | 
			
		||||
          name="is_password"
 | 
			
		||||
          v-decorator="['is_password', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
        />
 | 
			
		||||
      </a-form-item>
 | 
			
		||||
    </a-col>
 | 
			
		||||
    <a-col :span="6" v-if="currentValueType === '2'">
 | 
			
		||||
      <a-form-item :label-col="{ span: 8 }" :wrapper-col="horizontalFormItemLayout.wrapperCol" label="链接">
 | 
			
		||||
        <a-switch
 | 
			
		||||
          :disabled="isShowComputedArea"
 | 
			
		||||
          @change="(checked) => onChange(checked, 'is_link')"
 | 
			
		||||
          name="is_link"
 | 
			
		||||
          v-decorator="['is_link', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
        />
 | 
			
		||||
      </a-form-item>
 | 
			
		||||
    </a-col>
 | 
			
		||||
    <a-divider style="font-size:14px;margin-top:6px;">高级设置</a-divider>
 | 
			
		||||
    <a-row>
 | 
			
		||||
      <a-col :span="24">
 | 
			
		||||
@@ -294,12 +285,12 @@
 | 
			
		||||
          <FontArea ref="fontArea" />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
      <a-col :span="24" v-if="currentValueType !== '6'">
 | 
			
		||||
      <a-col :span="24" v-if="!['6', '7'].includes(currentValueType)">
 | 
			
		||||
        <a-form-item :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }" label="预定义值">
 | 
			
		||||
          <PreValueArea ref="preValueArea" :disabled="isShowComputedArea" />
 | 
			
		||||
          <PreValueArea ref="preValueArea" :canDefineScript="canDefineScript" :disabled="isShowComputedArea" />
 | 
			
		||||
        </a-form-item>
 | 
			
		||||
      </a-col>
 | 
			
		||||
      <a-col :span="24">
 | 
			
		||||
      <a-col :span="24" v-if="!['6', '7'].includes(currentValueType)">
 | 
			
		||||
        <a-form-item :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
 | 
			
		||||
          <template slot="label">
 | 
			
		||||
            <span
 | 
			
		||||
@@ -327,7 +318,7 @@
 | 
			
		||||
          <a-switch
 | 
			
		||||
            :disabled="!canDefineComputed"
 | 
			
		||||
            @change="(checked) => onChange(checked, 'is_computed')"
 | 
			
		||||
            name="is_password"
 | 
			
		||||
            name="is_computed"
 | 
			
		||||
            v-decorator="['is_computed', { rules: [], valuePropName: 'checked' }]"
 | 
			
		||||
          />
 | 
			
		||||
          <ComputedArea ref="computedArea" v-if="isShowComputedArea" :canDefineComputed="canDefineComputed" />
 | 
			
		||||
@@ -369,7 +360,7 @@ export default {
 | 
			
		||||
      valueTypeMap,
 | 
			
		||||
      formItemLayout: {
 | 
			
		||||
        labelCol: { span: 8 },
 | 
			
		||||
        wrapperCol: { span: 12 },
 | 
			
		||||
        wrapperCol: { span: 15 },
 | 
			
		||||
      },
 | 
			
		||||
      horizontalFormItemLayout: {
 | 
			
		||||
        labelCol: { span: 16 },
 | 
			
		||||
@@ -386,6 +377,11 @@ export default {
 | 
			
		||||
      defaultForDatetime: '',
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    canDefineScript() {
 | 
			
		||||
      return this.canDefineComputed
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    handleSubmit(isCloseModal = true) {
 | 
			
		||||
      this.form.validateFields(async (err, values) => {
 | 
			
		||||
@@ -428,7 +424,7 @@ export default {
 | 
			
		||||
            values = { ...values, ...computedAreaData }
 | 
			
		||||
          } else {
 | 
			
		||||
            // 如果是非计算属性,就看看有没有预定义值
 | 
			
		||||
            if (values.value_type !== '6') {
 | 
			
		||||
            if (!['6', '7'].includes(values.value_type)) {
 | 
			
		||||
              const preValueAreaData = this.$refs.preValueArea.getData()
 | 
			
		||||
              values = { ...values, ...preValueAreaData }
 | 
			
		||||
            }
 | 
			
		||||
@@ -437,17 +433,25 @@ export default {
 | 
			
		||||
 | 
			
		||||
          // is_index进行操作,除了文本   索引隐藏掉  文本  索引默认是true
 | 
			
		||||
          // 框里的5种类型  is_index=true
 | 
			
		||||
          // json类型  is_index=false
 | 
			
		||||
          if (values.value_type === '6') {
 | 
			
		||||
          // json类型、密码、链接  is_index=false
 | 
			
		||||
          if (['6', '7', '8'].includes(values.value_type)) {
 | 
			
		||||
            values.is_index = false
 | 
			
		||||
          } else if (values.value_type !== '2') {
 | 
			
		||||
            values.is_index = true
 | 
			
		||||
          }
 | 
			
		||||
          if (values.value_type === '7') {
 | 
			
		||||
            values.value_type = '2'
 | 
			
		||||
            values.is_password = true
 | 
			
		||||
          }
 | 
			
		||||
          if (values.value_type === '8') {
 | 
			
		||||
            values.value_type = '2'
 | 
			
		||||
            values.is_link = true
 | 
			
		||||
          }
 | 
			
		||||
          const { attr_id } = await createAttribute({ ...values, option: { fontOptions } })
 | 
			
		||||
 | 
			
		||||
          this.form.resetFields()
 | 
			
		||||
          this.currentValueType = '2'
 | 
			
		||||
          if (values.value_type !== '6') {
 | 
			
		||||
          if (!['6'].includes(values.value_type) && !values.is_password) {
 | 
			
		||||
            this.$refs.preValueArea.valueList = []
 | 
			
		||||
          }
 | 
			
		||||
          this.$emit('done', attr_id, data, isCloseModal)
 | 
			
		||||
@@ -485,29 +489,27 @@ export default {
 | 
			
		||||
            is_index: false,
 | 
			
		||||
            is_sortable: false,
 | 
			
		||||
          })
 | 
			
		||||
          if (this.currentValueType === '2') {
 | 
			
		||||
            this.form.setFieldsValue({
 | 
			
		||||
              is_password: false,
 | 
			
		||||
              is_link: false,
 | 
			
		||||
            })
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if (checked && property === 'is_password') {
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          is_link: false,
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (checked && property === 'is_link') {
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          is_password: false,
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (property === 'is_list') {
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          default_value: checked ? [] : '',
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (checked && property === 'is_sortable') {
 | 
			
		||||
        this.$message.warning('选中排序,则必须也要选中!')
 | 
			
		||||
        this.form.setFieldsValue({
 | 
			
		||||
          is_required: true,
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (!checked && property === 'is_required' && this.form.getFieldValue('is_sortable')) {
 | 
			
		||||
        this.$message.warning('选中排序,则必须也要选中!')
 | 
			
		||||
        this.$nextTick(() => {
 | 
			
		||||
          this.form.setFieldsValue({
 | 
			
		||||
            is_required: true,
 | 
			
		||||
          })
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    onJsonChange(value) {
 | 
			
		||||
      this.default_value_json_right = true
 | 
			
		||||
@@ -548,4 +550,8 @@ export default {
 | 
			
		||||
    background-color: #2f54eb;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
.value-type-des {
 | 
			
		||||
  font-size: 10px;
 | 
			
		||||
  color: #a9a9a9;
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,91 +1,90 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <a-tabs v-model="activeKey" size="small" :tabBarStyle="{ borderBottom: 'none' }">
 | 
			
		||||
    <a-tab-pane key="expr" :disabled="!canDefineComputed">
 | 
			
		||||
      <span style="font-size:12px;" slot="tab">表达式</span>
 | 
			
		||||
      <a-textarea v-model="compute_expr" :placeholder="`{{a}}+{{b}}`" :rows="2" :disabled="!canDefineComputed" />
 | 
			
		||||
    </a-tab-pane>
 | 
			
		||||
    <a-tab-pane key="script" :disabled="!canDefineComputed">
 | 
			
		||||
      <span style="font-size:12px;" slot="tab">代码</span>
 | 
			
		||||
      <codemirror style="z-index: 9999" :options="cmOptions" v-model="compute_script"></codemirror>
 | 
			
		||||
    </a-tab-pane>
 | 
			
		||||
    <template slot="tabBarExtraContent" v-if="showCalcComputed">
 | 
			
		||||
      <a-button type="primary" size="small" @click="handleCalcComputed">
 | 
			
		||||
        应用
 | 
			
		||||
      </a-button>
 | 
			
		||||
      <a-tooltip title="所有CI触发计算">
 | 
			
		||||
        <a-icon type="question-circle" style="margin-left:5px" />
 | 
			
		||||
      </a-tooltip>
 | 
			
		||||
    </template>
 | 
			
		||||
  </a-tabs>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { codemirror } from 'vue-codemirror'
 | 
			
		||||
import 'codemirror/lib/codemirror.css'
 | 
			
		||||
import 'codemirror/theme/monokai.css'
 | 
			
		||||
 | 
			
		||||
require('codemirror/mode/python/python.js')
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'ComputedArea',
 | 
			
		||||
  components: { codemirror },
 | 
			
		||||
  props: {
 | 
			
		||||
    canDefineComputed: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: true,
 | 
			
		||||
    },
 | 
			
		||||
    showCalcComputed: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: false,
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      activeKey: 'expr', // expr script
 | 
			
		||||
      compute_expr: '',
 | 
			
		||||
      compute_script: 'def computed(): \n   return',
 | 
			
		||||
      cmOptions: {
 | 
			
		||||
        lineNumbers: true,
 | 
			
		||||
        mode: 'python',
 | 
			
		||||
        height: '200px',
 | 
			
		||||
        theme: 'monokai',
 | 
			
		||||
        smartIndent: true,
 | 
			
		||||
        tabSize: 4,
 | 
			
		||||
        lineWrapping: true,
 | 
			
		||||
        readOnly: !this.canDefineComputed,
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    getData() {
 | 
			
		||||
      const { activeKey, compute_expr, compute_script } = this
 | 
			
		||||
      if (activeKey === 'expr') {
 | 
			
		||||
        return { compute_expr, compute_script: null }
 | 
			
		||||
      } else if (activeKey === 'script') {
 | 
			
		||||
        return { compute_script, compute_expr: null }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    setData(data) {
 | 
			
		||||
      const { compute_expr, compute_script } = data
 | 
			
		||||
      this.compute_expr = compute_expr
 | 
			
		||||
      this.compute_script = compute_script || 'def computed(): \n   return'
 | 
			
		||||
      if (compute_script) {
 | 
			
		||||
        this.activeKey = 'script'
 | 
			
		||||
      } else {
 | 
			
		||||
        this.activeKey = 'expr'
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleCalcComputed() {
 | 
			
		||||
      const that = this
 | 
			
		||||
      this.$confirm({
 | 
			
		||||
        title: '警告',
 | 
			
		||||
        content: `确认触发将保存当前配置及触发所有CI的计算?`,
 | 
			
		||||
        onOk() {
 | 
			
		||||
          that.$emit('handleCalcComputed')
 | 
			
		||||
        },
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
<template>
 | 
			
		||||
  <a-tabs v-model="activeKey" size="small" :tabBarStyle="{ borderBottom: 'none' }">
 | 
			
		||||
    <a-tab-pane key="expr" :disabled="!canDefineComputed">
 | 
			
		||||
      <span style="font-size:12px;" slot="tab">表达式</span>
 | 
			
		||||
      <a-textarea v-model="compute_expr" :placeholder="`{{a}}+{{b}}`" :rows="2" :disabled="!canDefineComputed" />
 | 
			
		||||
    </a-tab-pane>
 | 
			
		||||
    <a-tab-pane key="script" :disabled="!canDefineComputed">
 | 
			
		||||
      <span style="font-size:12px;" slot="tab">代码</span>
 | 
			
		||||
      <codemirror style="z-index: 9999" :options="cmOptions" v-model="compute_script"></codemirror>
 | 
			
		||||
    </a-tab-pane>
 | 
			
		||||
    <template slot="tabBarExtraContent" v-if="showCalcComputed">
 | 
			
		||||
      <a-button type="primary" size="small" @click="handleCalcComputed">
 | 
			
		||||
        应用
 | 
			
		||||
      </a-button>
 | 
			
		||||
      <a-tooltip title="所有CI触发计算">
 | 
			
		||||
        <a-icon type="question-circle" style="margin-left:5px" />
 | 
			
		||||
      </a-tooltip>
 | 
			
		||||
    </template>
 | 
			
		||||
  </a-tabs>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { codemirror } from 'vue-codemirror'
 | 
			
		||||
import 'codemirror/lib/codemirror.css'
 | 
			
		||||
import 'codemirror/theme/monokai.css'
 | 
			
		||||
 | 
			
		||||
require('codemirror/mode/python/python.js')
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'ComputedArea',
 | 
			
		||||
  components: { codemirror },
 | 
			
		||||
  props: {
 | 
			
		||||
    canDefineComputed: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: true,
 | 
			
		||||
    },
 | 
			
		||||
    showCalcComputed: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: false,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      activeKey: 'expr', // expr script
 | 
			
		||||
      compute_expr: '',
 | 
			
		||||
      compute_script: 'def computed(): \n   return',
 | 
			
		||||
      cmOptions: {
 | 
			
		||||
        lineNumbers: true,
 | 
			
		||||
        mode: 'python',
 | 
			
		||||
        height: '200px',
 | 
			
		||||
        theme: 'monokai',
 | 
			
		||||
        tabSize: 4,
 | 
			
		||||
        lineWrapping: true,
 | 
			
		||||
        readOnly: !this.canDefineComputed,
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    getData() {
 | 
			
		||||
      const { activeKey, compute_expr, compute_script } = this
 | 
			
		||||
      if (activeKey === 'expr') {
 | 
			
		||||
        return { compute_expr, compute_script: null }
 | 
			
		||||
      } else if (activeKey === 'script') {
 | 
			
		||||
        return { compute_script, compute_expr: null }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    setData(data) {
 | 
			
		||||
      const { compute_expr, compute_script } = data
 | 
			
		||||
      this.compute_expr = compute_expr
 | 
			
		||||
      this.compute_script = compute_script || 'def computed(): \n   return'
 | 
			
		||||
      if (compute_script) {
 | 
			
		||||
        this.activeKey = 'script'
 | 
			
		||||
      } else {
 | 
			
		||||
        this.activeKey = 'expr'
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    handleCalcComputed() {
 | 
			
		||||
      const that = this
 | 
			
		||||
      this.$confirm({
 | 
			
		||||
        title: '警告',
 | 
			
		||||
        content: `确认触发将保存当前配置及触发所有CI的计算?`,
 | 
			
		||||
        onOk() {
 | 
			
		||||
          that.$emit('handleCalcComputed')
 | 
			
		||||
        },
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,5 +1,11 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <a-tabs id="preValueArea" v-model="activeKey" size="small" :tabBarStyle="{ borderBottom: 'none' }">
 | 
			
		||||
  <a-tabs
 | 
			
		||||
    id="preValueArea"
 | 
			
		||||
    v-model="activeKey"
 | 
			
		||||
    @change="changeActiveKey"
 | 
			
		||||
    size="small"
 | 
			
		||||
    :tabBarStyle="{ borderBottom: 'none' }"
 | 
			
		||||
  >
 | 
			
		||||
    <a-tab-pane key="define" :disabled="disabled">
 | 
			
		||||
      <span style="font-size:12px;" slot="tab">定义</span>
 | 
			
		||||
      <PreValueTag type="add" :item="[]" @add="addNewValue" :disabled="disabled">
 | 
			
		||||
@@ -170,6 +176,15 @@
 | 
			
		||||
        </a-col>
 | 
			
		||||
      </a-row>
 | 
			
		||||
    </a-tab-pane>
 | 
			
		||||
    <a-tab-pane key="script" :disabled="disabled || !canDefineScript">
 | 
			
		||||
      <span style="font-size:12px;" slot="tab">脚本</span>
 | 
			
		||||
      <CustomCodeMirror
 | 
			
		||||
        codeMirrorId="cmdb-pre-value"
 | 
			
		||||
        ref="codemirror"
 | 
			
		||||
        @changeCodeContent="changeCodeContent"
 | 
			
		||||
      ></CustomCodeMirror>
 | 
			
		||||
      <!-- <codemirror style="z-index: 9999" :options="cmOptions" v-model="script"></codemirror> -->
 | 
			
		||||
    </a-tab-pane>
 | 
			
		||||
  </a-tabs>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
@@ -184,14 +199,22 @@ import { getCITypeGroups } from '../../api/ciTypeGroup'
 | 
			
		||||
import { getCITypeCommonAttributesByTypeIds } from '../../api/CITypeAttr'
 | 
			
		||||
import FilterComp from '@/components/CMDBFilterComp'
 | 
			
		||||
 | 
			
		||||
import CustomCodeMirror from '@/components/CustomCodeMirror'
 | 
			
		||||
import 'codemirror/lib/codemirror.css'
 | 
			
		||||
import 'codemirror/theme/monokai.css'
 | 
			
		||||
require('codemirror/mode/python/python.js')
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'PreValueArea',
 | 
			
		||||
  components: { draggable, PreValueTag, ColorPicker, Webhook, FilterComp },
 | 
			
		||||
  components: { draggable, PreValueTag, ColorPicker, Webhook, FilterComp, CustomCodeMirror },
 | 
			
		||||
  props: {
 | 
			
		||||
    disabled: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: true,
 | 
			
		||||
    },
 | 
			
		||||
    canDefineScript: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: false,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
@@ -208,6 +231,17 @@ export default {
 | 
			
		||||
      ciTypeGroup: [],
 | 
			
		||||
      typeAttrs: [],
 | 
			
		||||
      filterExp: '',
 | 
			
		||||
      script:
 | 
			
		||||
        'class ChoiceValue(object):\n    @staticmethod\n    def values():\n        """\n        执行入口, 返回预定义值\n        :return: 返回一个列表, 值的类型同属性的类型\n        例如:\n        return ["在线", "下线"]\n        """\n        return []',
 | 
			
		||||
      cmOptions: {
 | 
			
		||||
        lineNumbers: true,
 | 
			
		||||
        mode: 'python',
 | 
			
		||||
        height: '200px',
 | 
			
		||||
        theme: 'monokai',
 | 
			
		||||
        tabSize: 4,
 | 
			
		||||
        lineWrapping: true,
 | 
			
		||||
        readOnly: this.disabled || !this.canDefineScript,
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  watch: {
 | 
			
		||||
@@ -281,6 +315,14 @@ export default {
 | 
			
		||||
        const choice_web_hook = this.$refs.webhook.getParams()
 | 
			
		||||
        choice_web_hook.ret_key = this.form.ret_key
 | 
			
		||||
        return { choice_value: [], choice_web_hook, choice_other: null }
 | 
			
		||||
      } else if (this.activeKey === 'script') {
 | 
			
		||||
        return {
 | 
			
		||||
          choice_value: [],
 | 
			
		||||
          choice_web_hook: null,
 | 
			
		||||
          choice_other: {
 | 
			
		||||
            script: this.script,
 | 
			
		||||
          },
 | 
			
		||||
        }
 | 
			
		||||
      } else {
 | 
			
		||||
        let choice_other = {}
 | 
			
		||||
        if (this.choice_other.type_ids && this.choice_other.type_ids.length) {
 | 
			
		||||
@@ -302,14 +344,22 @@ export default {
 | 
			
		||||
          this.form.ret_key = choice_web_hook.ret_key ?? ''
 | 
			
		||||
        })
 | 
			
		||||
      } else if (choice_other) {
 | 
			
		||||
        this.activeKey = 'choice_other'
 | 
			
		||||
        const { type_ids, attr_id, filter } = choice_other
 | 
			
		||||
        this.choice_other = { type_ids, attr_id }
 | 
			
		||||
        this.filterExp = filter
 | 
			
		||||
        if (type_ids && type_ids.length) {
 | 
			
		||||
        if (choice_other.script) {
 | 
			
		||||
          this.activeKey = 'script'
 | 
			
		||||
          this.script = choice_other.script
 | 
			
		||||
          this.$nextTick(() => {
 | 
			
		||||
            this.$refs.filterComp.visibleChange(true, false)
 | 
			
		||||
            this.$refs.codemirror.initCodeMirror(choice_other.script)
 | 
			
		||||
          })
 | 
			
		||||
        } else {
 | 
			
		||||
          this.activeKey = 'choice_other'
 | 
			
		||||
          const { type_ids, attr_id, filter } = choice_other
 | 
			
		||||
          this.choice_other = { type_ids, attr_id }
 | 
			
		||||
          this.filterExp = filter
 | 
			
		||||
          if (type_ids && type_ids.length) {
 | 
			
		||||
            this.$nextTick(() => {
 | 
			
		||||
              this.$refs.filterComp.visibleChange(true, false)
 | 
			
		||||
            })
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      } else {
 | 
			
		||||
        this.valueList = choice_value
 | 
			
		||||
@@ -330,6 +380,16 @@ export default {
 | 
			
		||||
        this.filterExp = ''
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    changeCodeContent(value) {
 | 
			
		||||
      this.script = value && value.replace('\t', '    ')
 | 
			
		||||
    },
 | 
			
		||||
    changeActiveKey(value) {
 | 
			
		||||
      if (value === 'script') {
 | 
			
		||||
        this.$nextTick(() => {
 | 
			
		||||
          this.$refs.codemirror.initCodeMirror(this.script)
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,345 +1,344 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <CustomDrawer width="800px" :title="title" :visible="visible" @close="handleClose">
 | 
			
		||||
    <template v-if="adType === 'agent'">
 | 
			
		||||
      <a-form-model
 | 
			
		||||
        ref="autoDiscoveryForm"
 | 
			
		||||
        :model="form"
 | 
			
		||||
        :rules="rules"
 | 
			
		||||
        :label-col="{ span: 2 }"
 | 
			
		||||
        :wrapper-col="{ span: 20 }"
 | 
			
		||||
      >
 | 
			
		||||
        <a-divider :style="{ margin: '5px 0' }">基础设置</a-divider>
 | 
			
		||||
        <a-form-model-item label="名称" prop="name">
 | 
			
		||||
          <a-input v-model="form.name" />
 | 
			
		||||
        </a-form-model-item>
 | 
			
		||||
        <a-form-model-item label="图标" v-if="is_inner">
 | 
			
		||||
          <CustomIconSelect v-model="customIcon" :style="{ marginTop: '6px' }" />
 | 
			
		||||
        </a-form-model-item>
 | 
			
		||||
        <a-form-model-item label="模式" prop="is_plugin">
 | 
			
		||||
          <a-radio-group v-model="form.is_plugin" @change="changeIsPlugin" :disabled="!is_inner">
 | 
			
		||||
            <a-radio :value="false">默认</a-radio>
 | 
			
		||||
            <a-radio :value="true">plugin</a-radio>
 | 
			
		||||
          </a-radio-group>
 | 
			
		||||
        </a-form-model-item>
 | 
			
		||||
      </a-form-model>
 | 
			
		||||
      <a-divider :style="{ margin: '5px 0' }">采集设置</a-divider>
 | 
			
		||||
      <CustomCodeMirror
 | 
			
		||||
        codeMirrorId="cmdb-adt"
 | 
			
		||||
        v-if="form.is_plugin"
 | 
			
		||||
        ref="codemirror"
 | 
			
		||||
        @changeCodeContent="changeCodeContent"
 | 
			
		||||
      ></CustomCodeMirror>
 | 
			
		||||
      <div style="margin:10px 0;text-align:right;">
 | 
			
		||||
        <a-button
 | 
			
		||||
          v-show="form.is_plugin"
 | 
			
		||||
          size="small"
 | 
			
		||||
          type="primary"
 | 
			
		||||
          ghost
 | 
			
		||||
          @click="handleSubmit(true)"
 | 
			
		||||
        >更新字段</a-button
 | 
			
		||||
        >
 | 
			
		||||
      </div>
 | 
			
		||||
      <a-button
 | 
			
		||||
        v-show="!form.is_plugin"
 | 
			
		||||
        size="small"
 | 
			
		||||
        type="primary"
 | 
			
		||||
        ghost
 | 
			
		||||
        icon="plus"
 | 
			
		||||
        :style="{ marginBottom: '10px' }"
 | 
			
		||||
        @click="insertEvent(-1)"
 | 
			
		||||
      >新增</a-button
 | 
			
		||||
      >
 | 
			
		||||
      <vxe-table
 | 
			
		||||
        size="mini"
 | 
			
		||||
        stripe
 | 
			
		||||
        class="ops-stripe-table"
 | 
			
		||||
        show-overflow
 | 
			
		||||
        keep-source
 | 
			
		||||
        ref="xTable"
 | 
			
		||||
        max-height="400"
 | 
			
		||||
        :data="tableData"
 | 
			
		||||
        :edit-config="{ trigger: 'manual', mode: 'row' }"
 | 
			
		||||
      >
 | 
			
		||||
        <vxe-column field="name" title="名称" :edit-render="{ autofocus: '.vxe-input--inner' }">
 | 
			
		||||
          <template #edit="{ row }">
 | 
			
		||||
            <vxe-input v-model="row.name" type="text"></vxe-input>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
        <vxe-column field="type" title="类型" :edit-render="{}">
 | 
			
		||||
          <template #edit="{ row }">
 | 
			
		||||
            <vxe-select v-model="row.type" transfer>
 | 
			
		||||
              <vxe-option v-for="item in typeList" :key="item" :value="item" :label="item"></vxe-option>
 | 
			
		||||
            </vxe-select>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
        <vxe-column field="desc" title="描述" :edit-render="{ autofocus: '.vxe-input--inner' }">
 | 
			
		||||
          <template #edit="{ row }">
 | 
			
		||||
            <vxe-input v-model="row.desc" type="text"></vxe-input>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
        <vxe-column title="操作" width="60" v-if="!form.is_plugin">
 | 
			
		||||
          <template #default="{ row }">
 | 
			
		||||
            <a-space v-if="$refs.xTable.isActiveByRow(row)">
 | 
			
		||||
              <a @click="saveRowEvent(row)"><a-icon type="save"/></a>
 | 
			
		||||
              <a @click="cancelRowEvent(row)"><a-icon type="close"/></a>
 | 
			
		||||
            </a-space>
 | 
			
		||||
            <a-space v-else>
 | 
			
		||||
              <a @click="editRowEvent(row)"><a-icon type="edit"/></a>
 | 
			
		||||
              <a :style="{ color: 'red' }" @click="deleteRowEvent(row)"><a-icon type="delete"/></a>
 | 
			
		||||
            </a-space>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
      </vxe-table>
 | 
			
		||||
 | 
			
		||||
      <div class="custom-drawer-bottom-action">
 | 
			
		||||
        <a-button @click="handleClose">取消</a-button>
 | 
			
		||||
        <a-button @click="handleSubmit(false)" type="primary">保存</a-button>
 | 
			
		||||
      </div>
 | 
			
		||||
    </template>
 | 
			
		||||
    <template v-else>
 | 
			
		||||
      <HttpSnmpAD ref="httpSnmpAd" :ruleType="adType" :ruleName="ruleData.name" />
 | 
			
		||||
    </template>
 | 
			
		||||
  </CustomDrawer>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import CustomIconSelect from '@/components/CustomIconSelect'
 | 
			
		||||
import { postDiscovery, putDiscovery } from '../../api/discovery'
 | 
			
		||||
import HttpSnmpAD from '../../components/httpSnmpAD'
 | 
			
		||||
import CustomCodeMirror from '@/components/CustomCodeMirror'
 | 
			
		||||
import 'codemirror/lib/codemirror.css'
 | 
			
		||||
import 'codemirror/theme/monokai.css'
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'EditDrawer',
 | 
			
		||||
  components: { CustomIconSelect, CustomCodeMirror, HttpSnmpAD },
 | 
			
		||||
  props: {
 | 
			
		||||
    is_inner: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: true,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    const default_plugin_script = `# -*- coding:utf-8 -*-
 | 
			
		||||
 | 
			
		||||
import json
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AutoDiscovery(object):
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def unique_key(self):
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        :return: 返回唯一属性的名字
 | 
			
		||||
        """
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def attributes():
 | 
			
		||||
        """
 | 
			
		||||
        定义属性字段
 | 
			
		||||
        :return: 返回属性字段列表, 列表项是(名称, 类型, 描述), 名称必须是英文
 | 
			
		||||
        类型: String Integer Float Date DateTime Time JSON
 | 
			
		||||
        例如:
 | 
			
		||||
        return [
 | 
			
		||||
            ("ci_type", "String", "模型名称"),
 | 
			
		||||
            ("private_ip", "String", "内网IP, 多值逗号分隔")
 | 
			
		||||
        ]
 | 
			
		||||
        """
 | 
			
		||||
        return []
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def run():
 | 
			
		||||
        """
 | 
			
		||||
        执行入口, 返回采集的属性值
 | 
			
		||||
        :return: 返回一个列表, 列表项是字典, 字典key是属性名称, value是属性值
 | 
			
		||||
        例如:
 | 
			
		||||
        return [dict(ci_type="server", private_ip="192.168.1.1")]
 | 
			
		||||
        """
 | 
			
		||||
        return []
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    result = AutoDiscovery().run()
 | 
			
		||||
    if isinstance(result, list):
 | 
			
		||||
        print("AutoDiscovery::Result::{}".format(json.dumps(result)))
 | 
			
		||||
    else:
 | 
			
		||||
        print("ERROR: 采集返回必须是列表")
 | 
			
		||||
          `
 | 
			
		||||
    const typeList = ['String', 'Integer', 'Float', 'Date', 'DateTime', 'Time', 'JSON']
 | 
			
		||||
    return {
 | 
			
		||||
      default_plugin_script,
 | 
			
		||||
      typeList,
 | 
			
		||||
      visible: false,
 | 
			
		||||
      ruleData: {},
 | 
			
		||||
      type: 'add',
 | 
			
		||||
      adType: '',
 | 
			
		||||
      form: { name: '', is_plugin: false },
 | 
			
		||||
      rules: {},
 | 
			
		||||
      customIcon: { name: '', color: '' },
 | 
			
		||||
      tableData: [],
 | 
			
		||||
      editDefaultTableData: [],
 | 
			
		||||
      plugin_script: '',
 | 
			
		||||
      cmOptions: {
 | 
			
		||||
        lineNumbers: true,
 | 
			
		||||
        mode: 'python',
 | 
			
		||||
        height: '200px',
 | 
			
		||||
        theme: 'monokai',
 | 
			
		||||
        smartIndent: true,
 | 
			
		||||
        tabSize: 4,
 | 
			
		||||
        lineWrapping: true,
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    title() {
 | 
			
		||||
      if (this.adType === 'http' || this.adType === 'snmp') {
 | 
			
		||||
        return this.ruleData.name
 | 
			
		||||
      }
 | 
			
		||||
      if (this.type === 'edit') {
 | 
			
		||||
        return `编辑:${this.ruleData.name}`
 | 
			
		||||
      }
 | 
			
		||||
      return '新建'
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  inject: {
 | 
			
		||||
    getDiscovery: {
 | 
			
		||||
      from: 'getDiscovery',
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    open(data, type, adType) {
 | 
			
		||||
      this.visible = true
 | 
			
		||||
      this.type = type
 | 
			
		||||
      this.ruleData = data
 | 
			
		||||
      this.adType = adType
 | 
			
		||||
      if (!this.is_inner) {
 | 
			
		||||
        this.form = {
 | 
			
		||||
          name: '',
 | 
			
		||||
          is_plugin: true,
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if (adType === 'http' || adType === 'snmp') {
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      this.$nextTick(() => {
 | 
			
		||||
        if (this.type === 'edit') {
 | 
			
		||||
          this.form = {
 | 
			
		||||
            name: data.name,
 | 
			
		||||
            is_plugin: data.is_plugin,
 | 
			
		||||
          }
 | 
			
		||||
          this.customIcon = data?.option?.icon ?? { name: 'caise-chajian', color: '' }
 | 
			
		||||
          this.tableData = data?.attributes ?? []
 | 
			
		||||
          this.editDefaultTableData = data?.attributes ?? []
 | 
			
		||||
          this.plugin_script = data?.plugin_script ?? this.default_plugin_script
 | 
			
		||||
        }
 | 
			
		||||
        if (this.type === 'add') {
 | 
			
		||||
          this.customIcon = { name: 'caise-chajian', color: '' }
 | 
			
		||||
          // eslint-disable-next-line no-useless-escape
 | 
			
		||||
          this.plugin_script = this.default_plugin_script
 | 
			
		||||
        }
 | 
			
		||||
        if (data?.is_plugin || !this.is_inner) {
 | 
			
		||||
          this.$nextTick(() => {
 | 
			
		||||
            this.$refs.codemirror.initCodeMirror(this.plugin_script)
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    handleClose() {
 | 
			
		||||
      this.tableData = []
 | 
			
		||||
      this.customIcon = { name: '', color: '' }
 | 
			
		||||
      this.form = { name: '', is_plugin: false }
 | 
			
		||||
      if (this.adType === 'agent') {
 | 
			
		||||
        this.$refs.autoDiscoveryForm.clearValidate()
 | 
			
		||||
      } else {
 | 
			
		||||
        // this.$refs.httpSnmpAd.currentCate = ''
 | 
			
		||||
      }
 | 
			
		||||
      this.visible = false
 | 
			
		||||
    },
 | 
			
		||||
    async insertEvent(row) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      const record = {}
 | 
			
		||||
      const { row: newRow } = await $table.insertAt(record, row)
 | 
			
		||||
      await $table.setEditRow(newRow)
 | 
			
		||||
    },
 | 
			
		||||
    editRowEvent(row) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      $table.setActiveRow(row)
 | 
			
		||||
    },
 | 
			
		||||
    saveRowEvent() {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      $table.clearActived().then(() => {
 | 
			
		||||
        this.loading = true
 | 
			
		||||
        setTimeout(() => {
 | 
			
		||||
          this.loading = false
 | 
			
		||||
        }, 300)
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    cancelRowEvent(row) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      $table.clearActived().then(() => {
 | 
			
		||||
        // 还原行数据
 | 
			
		||||
        $table.revertData(row)
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    deleteRowEvent(row) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      $table.remove(row)
 | 
			
		||||
    },
 | 
			
		||||
    async handleSubmit(isUpdateAttr = false) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      const { fullData: _tableData } = $table.getTableData()
 | 
			
		||||
      console.log(_tableData)
 | 
			
		||||
      const params = {
 | 
			
		||||
        ...this.form,
 | 
			
		||||
        type: this.adType,
 | 
			
		||||
        is_inner: this.is_inner,
 | 
			
		||||
        option: { icon: this.customIcon },
 | 
			
		||||
        attributes: this.form.is_plugin
 | 
			
		||||
          ? undefined
 | 
			
		||||
          : _tableData.map(({ name, alias, desc, type }) => {
 | 
			
		||||
              return { name, alias, desc, type }
 | 
			
		||||
            }),
 | 
			
		||||
        plugin_script: this.form.is_plugin ? this.plugin_script : undefined,
 | 
			
		||||
      }
 | 
			
		||||
      let res
 | 
			
		||||
      if (this.type === 'add') {
 | 
			
		||||
        res = await postDiscovery(params)
 | 
			
		||||
      } else {
 | 
			
		||||
        res = await putDiscovery(this.ruleData.id, params)
 | 
			
		||||
      }
 | 
			
		||||
      if (isUpdateAttr) {
 | 
			
		||||
        this.tableData = res.attributes
 | 
			
		||||
        this.type = 'edit'
 | 
			
		||||
        this.ruleData = res
 | 
			
		||||
        this.$message.success('更新成功!')
 | 
			
		||||
        if (this.is_inner) {
 | 
			
		||||
          this.getDiscovery()
 | 
			
		||||
        }
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      this.handleClose()
 | 
			
		||||
      console.log(this.is_inner)
 | 
			
		||||
      if (this.is_inner) {
 | 
			
		||||
        this.$message.success('保存成功!')
 | 
			
		||||
        this.getDiscovery()
 | 
			
		||||
      } else {
 | 
			
		||||
        this.$emit('updateNotInner', res)
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    changeIsPlugin(e) {
 | 
			
		||||
      if (e.target.value) {
 | 
			
		||||
        this.$nextTick(() => {
 | 
			
		||||
          this.$refs.codemirror.initCodeMirror(this.plugin_script)
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    changeCodeContent(value) {
 | 
			
		||||
      this.plugin_script = value && value.replace('\t', '    ')
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
<template>
 | 
			
		||||
  <CustomDrawer width="800px" :title="title" :visible="visible" @close="handleClose">
 | 
			
		||||
    <template v-if="adType === 'agent'">
 | 
			
		||||
      <a-form-model
 | 
			
		||||
        ref="autoDiscoveryForm"
 | 
			
		||||
        :model="form"
 | 
			
		||||
        :rules="rules"
 | 
			
		||||
        :label-col="{ span: 2 }"
 | 
			
		||||
        :wrapper-col="{ span: 20 }"
 | 
			
		||||
      >
 | 
			
		||||
        <a-divider :style="{ margin: '5px 0' }">基础设置</a-divider>
 | 
			
		||||
        <a-form-model-item label="名称" prop="name">
 | 
			
		||||
          <a-input v-model="form.name" />
 | 
			
		||||
        </a-form-model-item>
 | 
			
		||||
        <a-form-model-item label="图标" v-if="is_inner">
 | 
			
		||||
          <CustomIconSelect v-model="customIcon" :style="{ marginTop: '6px' }" />
 | 
			
		||||
        </a-form-model-item>
 | 
			
		||||
        <a-form-model-item label="模式" prop="is_plugin">
 | 
			
		||||
          <a-radio-group v-model="form.is_plugin" @change="changeIsPlugin" :disabled="!is_inner">
 | 
			
		||||
            <a-radio :value="false">默认</a-radio>
 | 
			
		||||
            <a-radio :value="true">plugin</a-radio>
 | 
			
		||||
          </a-radio-group>
 | 
			
		||||
        </a-form-model-item>
 | 
			
		||||
      </a-form-model>
 | 
			
		||||
      <a-divider :style="{ margin: '5px 0' }">采集设置</a-divider>
 | 
			
		||||
      <CustomCodeMirror
 | 
			
		||||
        codeMirrorId="cmdb-adt"
 | 
			
		||||
        v-if="form.is_plugin"
 | 
			
		||||
        ref="codemirror"
 | 
			
		||||
        @changeCodeContent="changeCodeContent"
 | 
			
		||||
      ></CustomCodeMirror>
 | 
			
		||||
      <div style="margin:10px 0;text-align:right;">
 | 
			
		||||
        <a-button
 | 
			
		||||
          v-show="form.is_plugin"
 | 
			
		||||
          size="small"
 | 
			
		||||
          type="primary"
 | 
			
		||||
          ghost
 | 
			
		||||
          @click="handleSubmit(true)"
 | 
			
		||||
        >更新字段</a-button
 | 
			
		||||
        >
 | 
			
		||||
      </div>
 | 
			
		||||
      <a-button
 | 
			
		||||
        v-show="!form.is_plugin"
 | 
			
		||||
        size="small"
 | 
			
		||||
        type="primary"
 | 
			
		||||
        ghost
 | 
			
		||||
        icon="plus"
 | 
			
		||||
        :style="{ marginBottom: '10px' }"
 | 
			
		||||
        @click="insertEvent(-1)"
 | 
			
		||||
      >新增</a-button
 | 
			
		||||
      >
 | 
			
		||||
      <vxe-table
 | 
			
		||||
        size="mini"
 | 
			
		||||
        stripe
 | 
			
		||||
        class="ops-stripe-table"
 | 
			
		||||
        show-overflow
 | 
			
		||||
        keep-source
 | 
			
		||||
        ref="xTable"
 | 
			
		||||
        max-height="400"
 | 
			
		||||
        :data="tableData"
 | 
			
		||||
        :edit-config="{ trigger: 'manual', mode: 'row' }"
 | 
			
		||||
      >
 | 
			
		||||
        <vxe-column field="name" title="名称" :edit-render="{ autofocus: '.vxe-input--inner' }">
 | 
			
		||||
          <template #edit="{ row }">
 | 
			
		||||
            <vxe-input v-model="row.name" type="text"></vxe-input>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
        <vxe-column field="type" title="类型" :edit-render="{}">
 | 
			
		||||
          <template #edit="{ row }">
 | 
			
		||||
            <vxe-select v-model="row.type" transfer>
 | 
			
		||||
              <vxe-option v-for="item in typeList" :key="item" :value="item" :label="item"></vxe-option>
 | 
			
		||||
            </vxe-select>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
        <vxe-column field="desc" title="描述" :edit-render="{ autofocus: '.vxe-input--inner' }">
 | 
			
		||||
          <template #edit="{ row }">
 | 
			
		||||
            <vxe-input v-model="row.desc" type="text"></vxe-input>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
        <vxe-column title="操作" width="60" v-if="!form.is_plugin">
 | 
			
		||||
          <template #default="{ row }">
 | 
			
		||||
            <a-space v-if="$refs.xTable.isActiveByRow(row)">
 | 
			
		||||
              <a @click="saveRowEvent(row)"><a-icon type="save"/></a>
 | 
			
		||||
              <a @click="cancelRowEvent(row)"><a-icon type="close"/></a>
 | 
			
		||||
            </a-space>
 | 
			
		||||
            <a-space v-else>
 | 
			
		||||
              <a @click="editRowEvent(row)"><a-icon type="edit"/></a>
 | 
			
		||||
              <a :style="{ color: 'red' }" @click="deleteRowEvent(row)"><a-icon type="delete"/></a>
 | 
			
		||||
            </a-space>
 | 
			
		||||
          </template>
 | 
			
		||||
        </vxe-column>
 | 
			
		||||
      </vxe-table>
 | 
			
		||||
 | 
			
		||||
      <div class="custom-drawer-bottom-action">
 | 
			
		||||
        <a-button @click="handleClose">取消</a-button>
 | 
			
		||||
        <a-button @click="handleSubmit(false)" type="primary">保存</a-button>
 | 
			
		||||
      </div>
 | 
			
		||||
    </template>
 | 
			
		||||
    <template v-else>
 | 
			
		||||
      <HttpSnmpAD ref="httpSnmpAd" :ruleType="adType" :ruleName="ruleData.name" />
 | 
			
		||||
    </template>
 | 
			
		||||
  </CustomDrawer>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import CustomIconSelect from '@/components/CustomIconSelect'
 | 
			
		||||
import { postDiscovery, putDiscovery } from '../../api/discovery'
 | 
			
		||||
import HttpSnmpAD from '../../components/httpSnmpAD'
 | 
			
		||||
import CustomCodeMirror from '@/components/CustomCodeMirror'
 | 
			
		||||
import 'codemirror/lib/codemirror.css'
 | 
			
		||||
import 'codemirror/theme/monokai.css'
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'EditDrawer',
 | 
			
		||||
  components: { CustomIconSelect, CustomCodeMirror, HttpSnmpAD },
 | 
			
		||||
  props: {
 | 
			
		||||
    is_inner: {
 | 
			
		||||
      type: Boolean,
 | 
			
		||||
      default: true,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    const default_plugin_script = `# -*- coding:utf-8 -*-
 | 
			
		||||
 | 
			
		||||
import json
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AutoDiscovery(object):
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def unique_key(self):
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        :return: 返回唯一属性的名字
 | 
			
		||||
        """
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def attributes():
 | 
			
		||||
        """
 | 
			
		||||
        定义属性字段
 | 
			
		||||
        :return: 返回属性字段列表, 列表项是(名称, 类型, 描述), 名称必须是英文
 | 
			
		||||
        类型: String Integer Float Date DateTime Time JSON
 | 
			
		||||
        例如:
 | 
			
		||||
        return [
 | 
			
		||||
            ("ci_type", "String", "模型名称"),
 | 
			
		||||
            ("private_ip", "String", "内网IP, 多值逗号分隔")
 | 
			
		||||
        ]
 | 
			
		||||
        """
 | 
			
		||||
        return []
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def run():
 | 
			
		||||
        """
 | 
			
		||||
        执行入口, 返回采集的属性值
 | 
			
		||||
        :return: 返回一个列表, 列表项是字典, 字典key是属性名称, value是属性值
 | 
			
		||||
        例如:
 | 
			
		||||
        return [dict(ci_type="server", private_ip="192.168.1.1")]
 | 
			
		||||
        """
 | 
			
		||||
        return []
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    result = AutoDiscovery().run()
 | 
			
		||||
    if isinstance(result, list):
 | 
			
		||||
        print("AutoDiscovery::Result::{}".format(json.dumps(result)))
 | 
			
		||||
    else:
 | 
			
		||||
        print("ERROR: 采集返回必须是列表")
 | 
			
		||||
          `
 | 
			
		||||
    const typeList = ['String', 'Integer', 'Float', 'Date', 'DateTime', 'Time', 'JSON']
 | 
			
		||||
    return {
 | 
			
		||||
      default_plugin_script,
 | 
			
		||||
      typeList,
 | 
			
		||||
      visible: false,
 | 
			
		||||
      ruleData: {},
 | 
			
		||||
      type: 'add',
 | 
			
		||||
      adType: '',
 | 
			
		||||
      form: { name: '', is_plugin: false },
 | 
			
		||||
      rules: {},
 | 
			
		||||
      customIcon: { name: '', color: '' },
 | 
			
		||||
      tableData: [],
 | 
			
		||||
      editDefaultTableData: [],
 | 
			
		||||
      plugin_script: '',
 | 
			
		||||
      cmOptions: {
 | 
			
		||||
        lineNumbers: true,
 | 
			
		||||
        mode: 'python',
 | 
			
		||||
        height: '200px',
 | 
			
		||||
        theme: 'monokai',
 | 
			
		||||
        tabSize: 4,
 | 
			
		||||
        lineWrapping: true,
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    title() {
 | 
			
		||||
      if (this.adType === 'http' || this.adType === 'snmp') {
 | 
			
		||||
        return this.ruleData.name
 | 
			
		||||
      }
 | 
			
		||||
      if (this.type === 'edit') {
 | 
			
		||||
        return `编辑:${this.ruleData.name}`
 | 
			
		||||
      }
 | 
			
		||||
      return '新建'
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  inject: {
 | 
			
		||||
    getDiscovery: {
 | 
			
		||||
      from: 'getDiscovery',
 | 
			
		||||
      default: () => {},
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    open(data, type, adType) {
 | 
			
		||||
      this.visible = true
 | 
			
		||||
      this.type = type
 | 
			
		||||
      this.ruleData = data
 | 
			
		||||
      this.adType = adType
 | 
			
		||||
      if (!this.is_inner) {
 | 
			
		||||
        this.form = {
 | 
			
		||||
          name: '',
 | 
			
		||||
          is_plugin: true,
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if (adType === 'http' || adType === 'snmp') {
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      this.$nextTick(() => {
 | 
			
		||||
        if (this.type === 'edit') {
 | 
			
		||||
          this.form = {
 | 
			
		||||
            name: data.name,
 | 
			
		||||
            is_plugin: data.is_plugin,
 | 
			
		||||
          }
 | 
			
		||||
          this.customIcon = data?.option?.icon ?? { name: 'caise-chajian', color: '' }
 | 
			
		||||
          this.tableData = data?.attributes ?? []
 | 
			
		||||
          this.editDefaultTableData = data?.attributes ?? []
 | 
			
		||||
          this.plugin_script = data?.plugin_script ?? this.default_plugin_script
 | 
			
		||||
        }
 | 
			
		||||
        if (this.type === 'add') {
 | 
			
		||||
          this.customIcon = { name: 'caise-chajian', color: '' }
 | 
			
		||||
          // eslint-disable-next-line no-useless-escape
 | 
			
		||||
          this.plugin_script = this.default_plugin_script
 | 
			
		||||
        }
 | 
			
		||||
        if (data?.is_plugin || !this.is_inner) {
 | 
			
		||||
          this.$nextTick(() => {
 | 
			
		||||
            this.$refs.codemirror.initCodeMirror(this.plugin_script)
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    handleClose() {
 | 
			
		||||
      this.tableData = []
 | 
			
		||||
      this.customIcon = { name: '', color: '' }
 | 
			
		||||
      this.form = { name: '', is_plugin: false }
 | 
			
		||||
      if (this.adType === 'agent') {
 | 
			
		||||
        this.$refs.autoDiscoveryForm.clearValidate()
 | 
			
		||||
      } else {
 | 
			
		||||
        // this.$refs.httpSnmpAd.currentCate = ''
 | 
			
		||||
      }
 | 
			
		||||
      this.visible = false
 | 
			
		||||
    },
 | 
			
		||||
    async insertEvent(row) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      const record = {}
 | 
			
		||||
      const { row: newRow } = await $table.insertAt(record, row)
 | 
			
		||||
      await $table.setEditRow(newRow)
 | 
			
		||||
    },
 | 
			
		||||
    editRowEvent(row) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      $table.setActiveRow(row)
 | 
			
		||||
    },
 | 
			
		||||
    saveRowEvent() {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      $table.clearActived().then(() => {
 | 
			
		||||
        this.loading = true
 | 
			
		||||
        setTimeout(() => {
 | 
			
		||||
          this.loading = false
 | 
			
		||||
        }, 300)
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    cancelRowEvent(row) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      $table.clearActived().then(() => {
 | 
			
		||||
        // 还原行数据
 | 
			
		||||
        $table.revertData(row)
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    deleteRowEvent(row) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      $table.remove(row)
 | 
			
		||||
    },
 | 
			
		||||
    async handleSubmit(isUpdateAttr = false) {
 | 
			
		||||
      const $table = this.$refs.xTable
 | 
			
		||||
      const { fullData: _tableData } = $table.getTableData()
 | 
			
		||||
      console.log(_tableData)
 | 
			
		||||
      const params = {
 | 
			
		||||
        ...this.form,
 | 
			
		||||
        type: this.adType,
 | 
			
		||||
        is_inner: this.is_inner,
 | 
			
		||||
        option: { icon: this.customIcon },
 | 
			
		||||
        attributes: this.form.is_plugin
 | 
			
		||||
          ? undefined
 | 
			
		||||
          : _tableData.map(({ name, alias, desc, type }) => {
 | 
			
		||||
              return { name, alias, desc, type }
 | 
			
		||||
            }),
 | 
			
		||||
        plugin_script: this.form.is_plugin ? this.plugin_script : undefined,
 | 
			
		||||
      }
 | 
			
		||||
      let res
 | 
			
		||||
      if (this.type === 'add') {
 | 
			
		||||
        res = await postDiscovery(params)
 | 
			
		||||
      } else {
 | 
			
		||||
        res = await putDiscovery(this.ruleData.id, params)
 | 
			
		||||
      }
 | 
			
		||||
      if (isUpdateAttr) {
 | 
			
		||||
        this.tableData = res.attributes
 | 
			
		||||
        this.type = 'edit'
 | 
			
		||||
        this.ruleData = res
 | 
			
		||||
        this.$message.success('更新成功!')
 | 
			
		||||
        if (this.is_inner) {
 | 
			
		||||
          this.getDiscovery()
 | 
			
		||||
        }
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      this.handleClose()
 | 
			
		||||
      console.log(this.is_inner)
 | 
			
		||||
      if (this.is_inner) {
 | 
			
		||||
        this.$message.success('保存成功!')
 | 
			
		||||
        this.getDiscovery()
 | 
			
		||||
      } else {
 | 
			
		||||
        this.$emit('updateNotInner', res)
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    changeIsPlugin(e) {
 | 
			
		||||
      if (e.target.value) {
 | 
			
		||||
        this.$nextTick(() => {
 | 
			
		||||
          this.$refs.codemirror.initCodeMirror(this.plugin_script)
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    changeCodeContent(value) {
 | 
			
		||||
      this.plugin_script = value && value.replace('\t', '    ')
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style></style>
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,7 @@
 | 
			
		||||
              :expandedKeys="expandedKeys"
 | 
			
		||||
            >
 | 
			
		||||
              <a-icon slot="switcherIcon" type="down" />
 | 
			
		||||
              <template #title="{ key: treeKey, title, isLeaf }">
 | 
			
		||||
              <template #title="{ key: treeKey, title,isLeaf }">
 | 
			
		||||
                <ContextMenu
 | 
			
		||||
                  :title="title"
 | 
			
		||||
                  :treeKey="treeKey"
 | 
			
		||||
@@ -135,7 +135,8 @@
 | 
			
		||||
                    {{ col.title }}</span
 | 
			
		||||
                  >
 | 
			
		||||
                </template>
 | 
			
		||||
                <template v-if="col.is_choice" #edit="{ row }">
 | 
			
		||||
                <template v-if="col.is_choice || col.is_password" #edit="{ row }">
 | 
			
		||||
                  <vxe-input v-if="col.is_password" v-model="passwordValue[col.field]" />
 | 
			
		||||
                  <a-select
 | 
			
		||||
                    :getPopupContainer="(trigger) => trigger.parentElement"
 | 
			
		||||
                    :style="{ width: '100%', height: '32px' }"
 | 
			
		||||
@@ -177,10 +178,20 @@
 | 
			
		||||
                  #default="{row}"
 | 
			
		||||
                >
 | 
			
		||||
                  <span v-if="col.value_type === '6' && row[col.field]">{{ row[col.field] }}</span>
 | 
			
		||||
                  <a v-else-if="col.is_link" :href="`${row[col.field]}`" target="_blank">{{ row[col.field] }}</a>
 | 
			
		||||
                  <a
 | 
			
		||||
                    v-else-if="col.is_link && row[col.field]"
 | 
			
		||||
                    :href="
 | 
			
		||||
                      row[col.field].startsWith('http') || row[col.field].startsWith('https')
 | 
			
		||||
                        ? `${row[col.field]}`
 | 
			
		||||
                        : `http://${row[col.field]}`
 | 
			
		||||
                    "
 | 
			
		||||
                    target="_blank"
 | 
			
		||||
                  >{{ row[col.field] }}</a
 | 
			
		||||
                  >
 | 
			
		||||
                  <PasswordField
 | 
			
		||||
                    v-else-if="col.is_password && row[col.field]"
 | 
			
		||||
                    :password="row[col.field]"
 | 
			
		||||
                    :ci_id="row._id"
 | 
			
		||||
                    :attr_id="col.attr_id"
 | 
			
		||||
                  ></PasswordField>
 | 
			
		||||
                  <template v-else-if="col.is_choice">
 | 
			
		||||
                    <template v-if="col.is_list">
 | 
			
		||||
@@ -333,7 +344,7 @@ import {
 | 
			
		||||
} from '@/modules/cmdb/api/CIRelation'
 | 
			
		||||
 | 
			
		||||
import { getCITypeAttributesById } from '@/modules/cmdb/api/CITypeAttr'
 | 
			
		||||
import { searchCI2, updateCI, deleteCI } from '@/modules/cmdb/api/ci'
 | 
			
		||||
import { searchCI2, updateCI, deleteCI, searchCI } from '@/modules/cmdb/api/ci'
 | 
			
		||||
import { getCITypes } from '../../api/CIType'
 | 
			
		||||
import { roleHasPermissionToGrant } from '@/modules/acl/api/permission'
 | 
			
		||||
import { searchResourceType } from '@/modules/acl/api/resource'
 | 
			
		||||
@@ -347,6 +358,7 @@ import PasswordField from '../../components/passwordField/index.vue'
 | 
			
		||||
import PreferenceSearch from '../../components/preferenceSearch/preferenceSearch.vue'
 | 
			
		||||
import CMDBGrant from '../../components/cmdbGrant'
 | 
			
		||||
import { ops_move_icon as OpsMoveIcon } from '@/core/icons'
 | 
			
		||||
import { getAttrPassword } from '../../api/CITypeAttr'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  name: 'RelationViews',
 | 
			
		||||
@@ -407,6 +419,11 @@ export default {
 | 
			
		||||
      tableDragClassName: [],
 | 
			
		||||
 | 
			
		||||
      resource_type: {},
 | 
			
		||||
 | 
			
		||||
      initialPasswordValue: {},
 | 
			
		||||
      passwordValue: {},
 | 
			
		||||
      lastEditCiId: null,
 | 
			
		||||
      isContinueCloseEdit: true,
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
@@ -890,6 +907,12 @@ export default {
 | 
			
		||||
    calcColumns() {
 | 
			
		||||
      const width = document.getElementById('relation-views-right').clientWidth
 | 
			
		||||
      this.columns = getCITableColumns(this.instanceList, this.preferenceAttrList, width)
 | 
			
		||||
      this.columns.forEach((col) => {
 | 
			
		||||
        if (col.is_password) {
 | 
			
		||||
          this.initialPasswordValue[col.field] = ''
 | 
			
		||||
          this.passwordValue[col.field] = ''
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
      this.$nextTick(() => {
 | 
			
		||||
        this.$refs.xTable.refreshColumn()
 | 
			
		||||
      })
 | 
			
		||||
@@ -1076,15 +1099,47 @@ export default {
 | 
			
		||||
      }
 | 
			
		||||
      return _editRender
 | 
			
		||||
    },
 | 
			
		||||
    handleEditActived() {},
 | 
			
		||||
    handleEditActived() {
 | 
			
		||||
      const passwordCol = this.columns.filter((col) => col.is_password)
 | 
			
		||||
      this.$nextTick(() => {
 | 
			
		||||
        const editRecord = this.$refs.xTable.getVxetableRef().getEditRecord()
 | 
			
		||||
        const { row, column } = editRecord
 | 
			
		||||
        if (passwordCol.length && this.lastEditCiId !== row._id) {
 | 
			
		||||
          this.$nextTick(async () => {
 | 
			
		||||
            for (let i = 0; i < passwordCol.length; i++) {
 | 
			
		||||
              await getAttrPassword(row._id, passwordCol[i].attr_id).then((res) => {
 | 
			
		||||
                this.initialPasswordValue[passwordCol[i].field] = res.value
 | 
			
		||||
                this.passwordValue[passwordCol[i].field] = res.value
 | 
			
		||||
              })
 | 
			
		||||
            }
 | 
			
		||||
            this.isContinueCloseEdit = false
 | 
			
		||||
            await this.$refs.xTable.getVxetableRef().clearEdit()
 | 
			
		||||
            this.isContinueCloseEdit = true
 | 
			
		||||
            this.$nextTick(() => {
 | 
			
		||||
              this.$refs.xTable.getVxetableRef().setEditCell(row, column.field)
 | 
			
		||||
            })
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
        this.lastEditCiId = row._id
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    handleEditClose({ row, rowIndex, column }) {
 | 
			
		||||
      if (!this.isContinueCloseEdit) {
 | 
			
		||||
        return
 | 
			
		||||
      }
 | 
			
		||||
      const $table = this.$refs['xTable']
 | 
			
		||||
      const data = {}
 | 
			
		||||
      this.columns.forEach((item) => {
 | 
			
		||||
        if (!_.isEqual(row[item.field], this.initialInstanceList[rowIndex][item.field])) {
 | 
			
		||||
          data[item.field] = row[item.field] || null
 | 
			
		||||
          data[item.field] = row[item.field] ?? null
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
      Object.keys(this.initialPasswordValue).forEach((key) => {
 | 
			
		||||
        if (this.initialPasswordValue[key] !== this.passwordValue[key]) {
 | 
			
		||||
          data[key] = this.passwordValue[key]
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
      this.lastEditCiId = null
 | 
			
		||||
      if (JSON.stringify(data) !== '{}') {
 | 
			
		||||
        updateCI(row.ci_id || row._id, data)
 | 
			
		||||
          .then(() => {
 | 
			
		||||
@@ -1102,6 +1157,12 @@ export default {
 | 
			
		||||
            $table.revertData(row)
 | 
			
		||||
          })
 | 
			
		||||
      }
 | 
			
		||||
      this.columns.forEach((col) => {
 | 
			
		||||
        if (col.is_password) {
 | 
			
		||||
          this.initialPasswordValue[col.field] = ''
 | 
			
		||||
          this.passwordValue[col.field] = ''
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    deleteCI(record) {
 | 
			
		||||
      const that = this
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user