网易内推联系我哦

网易无偿内推,点击下方【首页】置顶帖查看说明

0%

普通调用

Python 脚本示例

# -*- coding: utf-8 -*-
import datetime

if __name__=='__main__':
    today = datetime.datetime.today()
    yesterday = today - datetime.timedelta(days=1)
    keyWord = yesterday.strftime( '%Y-%m-%d' )
    print(keyWord +" 测试!")

Shell 脚本示例

#! /bin/bash


thispath=$(cd "$(dirname "$0")"; pwd)

pyfile="$thispath/test.py"
result=`python $pyfile`
echo $result >> $thispath/out.log

调用结果

$ ./runAlarm.sh
2021-05-24 测试!

带参数调用

Python 脚本示例

# -*- coding: utf-8 -*-
import sys

if __name__=='__main__':
    print("param one:"+sys.argv[1])
    print("param two:"+sys.argv[2])

运行脚本:

$ python test0.py  a b
param one:a
param two:b

Shell 脚本示例

#! /bin/bash

thispath=$(cd "$(dirname "$0")"; pwd)

pyfile="$thispath/test0.py"
result=`python $pyfile ttt ccc`
echo $result

运行结果:

param one:ttt param two:ccc

向 Shell 脚本传递参数:

#! /bin/bash

thispath=$(cd "$(dirname "$0")"; pwd)

pyfile="$thispath/test0.py"
result=`python $pyfile $1 $2`
echo $result

运行结果:

$ bash test0.sh aaa bbb
param one:aaa param two:bbb

排除特定文件

<copy todir="${build.dir}" overwrite="true">
 <fileset dir="${src.dir}">
    <exclude name="**/*.java" /> <!-- 排除所有java文件 -->
    <exclude name="helloworld/" /> <!-- 排除根目录下整个helloworld文件夹 -->
    <exclude name="**/test/" /> <!-- 排除test子目录本身及其子目录下的所有文件夹 -->
  </fileset>
</copy>

动态添加属性

示例代码

<template>
    <div>
        <el-form :model="dataForm" label-width="100px">
            <el-form-item 
                v-for="(domain, index) in dataForm.domains"
                :label=domain.key
                :key="domain.key"
                :prop="'domains.' + index + '.value'"
                :rules="{ required: true, message: '属性不能为空', trigger: 'blur'}">
                <el-row>
                    <el-col :span="6">
                            <el-input v-model="domain.value"></el-input>
                    </el-col>
                    <el-col :span="4">
                            <el-button @click.prevent="removeDomain(domain)">删除</el-button>
                    </el-col>
                </el-row>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('dataForm')">提交属性 </el-button>
                <el-button @click="addDomain">新增属性</el-button>
            </el-form-item>
        </el-form>
     </div>
</template>
<script>
  export default {
    data() {
      return {
        dataForm: {
          domains: [{
            key: '属性a',
            value: 'aaa'
          }, {
            key: '属性b',
            value: 'bbb'
          }]
        }
      }
    },
    methods: {
      removeDomain(item) {
        var index = this.dataForm.domains.indexOf(item)
        if (index !== -1) {
          this.dataForm.domains.splice(index, 1)
        }
      },
      addDomain() {
        this.$prompt('请输入属性', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({ value }) => {
          this.dataForm.domains.push({
            value: '',
            key: value
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          })
        })
      }
    }
  }
</script>

实现效果

默认:

image-20210513153916188

增加属性:

image-20210513153943479

增加后:

image-20210513153956956

删除:

image-20210513154011220

动态添加输入框

示例代码

<template>
    <div>
        <el-form :model="dataForm" label-width="100px" size="small">
            <el-form-item label="名称匹配" prop="name">
              <el-row >
                <span v-for="(domain, index) in dataForm.domains">
                  <el-col :span="5">
                    <el-input v-model="domain.value"></el-input>
                  </el-col>
                  <el-col :span="2">
                    <el-button  @click="removeDomain(index)">删除</el-button>
                  </el-col>
                </span>
                <el-col :span="2">
                  <el-button  @click="addDomain">新增</el-button>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('dataForm')">提交属性 </el-button>
            </el-form-item>
        </el-form>
     </div>
</template>
<script>
  export default {
    data() {
      return {
        dataForm: {
          domains: [{value:"aaa"},{value:"bbb"},{value:"ccc"}]
        }
      }
    },
    methods: {
      removeDomain(index) {
        this.dataForm.domains.splice(index, 1)
      },
      addDomain() {
        this.dataForm.domains.push({value:""})
      }
    }
  }
</script>

实现效果

image-20210513170442637

优化效果

通过 clearable @clear='' 来实现删除效果。

<template>
    <div>
        <el-form :model="dataForm" label-width="100px" size="small">
            <el-form-item label="名称匹配" prop="name">
              <el-row >
                <el-col :span="3" v-for="(domain, index) in dataForm.domains" >
                  <el-input v-model="domain.value" clearable @clear="removeDomain(index)"></el-input>
                </el-col>
                <el-col :span="2">
                  <el-button  @click="addDomain">新增</el-button>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('dataForm')">提交属性 </el-button>
            </el-form-item>
        </el-form>
     </div>
</template>

image-20210513171431164