iview-admin:Table组件的使用

近在使用iview-admin开发prometheus和alertmanager管理平台,用到最多就是Table和Form两个组件了,本文重点介绍Table组件的使用。官方文档在 表格 - View Design (iviewui.com),如果有小伙伴有情趣可以去细看文档。

具体实例如下:

<template>
  <div>
    <Card>
      <tables ref="tables" v-model="tableData" :columns="columns"/>
    </Card>
  </div>
</template>

<script>
import Tables from '_c/tables'

export default {
  name: 'rules',
  components: {
    Tables
  },
  data () {
    
    return {
      tableData: [],
      columns: [
        { title: '编号', align: 'center', key: 'id', sortable: true },
        { title: '告警名称', align: 'center', key: 'alert_name' },
        {
          title: '告警等级',
          align: 'center',
          key: 'severity',
          render: (h, params) => {
            if (params.row.severity === 'warning') {
              return h('div', '警告')
            } else if (params.row.severity === 'critical') {
              return h('div', '危急')
            } else if (params.row.severity === 'emergency') {
              return h('div', '紧急')
            }
          }
        },
        { title: '表达式', align: 'center', key: 'expr' },
        { title: '持续时长', align: 'center', key: 'duration' },
        { title: '标题', align: 'center', key: 'summary' },
        { title: '描述', align: 'center', key: 'description' },
        { title: '数据源', align: 'center', key: 'datasource' },
        { title: '告警策略', align: 'center', key: 'group' },
        {
          title: '操作',
          align: 'center',
          type: 'operator',
          render: (h, params) => {
            return h('div', [
              h('a', {
                style: {
                  'margin-right': '10px',
                  'color': '#1890ff',
                  'font-size': '14px'
                },
                on: {
                  click: () => {
                    this.edit(params)
                  }
                }
              }, '编辑'),
              h('Poptip', {
                props: {
                  confirm: true,
                  title: '你确定要删除吗?'
                },
                on: {
                  'on-ok': () => {
                    this.delete(params)
                  }
                }
              }, [
                h('a', {
                  style: {
                    'margin-right': '10px',
                    'color': '#1890ff',
                    'font-size': '14px'
                  }
                }, '删除')
              ])
            ])
          }
        }
      ]
    }
  },
  methods: {
    initRulesData () {
      this.filterPromRule()
    },
    filterPromRule () {
      getPromRule().then(resp => {
        if (resp.data.code === 0) {
          this.tableData = resp.data.data
        } else {
          this.$Message.error('获取prometheus规则失败!')
        }
      })
    },
    edit (params) {
      this.prometheusRuleModel.id = params.row.id
      this.prometheusRuleModel.duration = params.row.duration
      this.prometheusRuleModel.datasource = params.row.datasource_id
      this.prometheusRuleModel.summary = params.row.summary
      this.prometheusRuleModel.description = params.row.description
      this.prometheusRuleModel.alertName = params.row.alert_name
      this.prometheusRuleModel.group = params.row.group_id
      this.prometheusRuleModel.severity = params.row.severity
      this.prometheusRuleModel.monitorMetrics = params.row.expr.split(/[><=]/)[0]
      this.prometheusRuleModel.alarmThreshold = params.row.expr.split(/[><=]/)[1]
      this.prometheusRuleModel.symbols = params.row.expr[params.row.expr.search(/[><=]/)]
      this.modalTitle = '修改prometheus告警规则'
      this.modalType = 'edit'
      this.createModal = true
    },
    delete (params) {
      deletePromRule(params.row.id).then(resp => {
        if (resp.data.code === 0) {
          this.initRulesData()
        } else {
          this.$Message.error('删除prometheus规则失败!')
        }
      })
    }
  },
  mounted () {
    this.initRulesData()
  }
}
</script>

<style>

</style>

{ "name": "iview-admin", "version": "2.0.0", "author": "Lison<lison16new@163.com>", "private": false, "scripts": { "dev": "vue-cli-service serve --open --mode development", "dev:prod": "vue-cli-service serve --open --mode production", "build": "vue-cli-service build", "build:dev": "vue-cli-service build --mode development", "dev-to-oss": "node deploy.js dat", "build:dev-to-oss": "vue-cli-service build --mode development && node deploy.js dat", "build:prod": "vue-cli-service build --mode production", "prod-to-oss": "node deploy.js prod", "build:prod-to-oss": "vue-cli-service build --mode production && node deploy.js prod", "oss:all": "yarn build:dev-to-oss && yarn build:prod-to-oss", "lint": "vue-cli-service lint", "test:unit": "vue-cli-service test:unit", "test:e2e": "vue-cli-service test:e2e" }, "dependencies": { "ali-oss": "^6.17.1", "axios": "^0.18.0", "clipboard": "^2.0.0", "codemirror": "^5.38.0", "countup": "^1.8.2", "cropperjs": "^1.2.2", "dayjs": "^1.7.7", "echarts": "^4.0.4", "html2canvas": "^1.0.0-alpha.12", "iview": "^3.2.2", "iview-area": "^1.5.17", "js-cookie": "^2.2.0", "simplemde": "^1.11.2", "sortablejs": "^1.7.0", "tree-table-vue": "^1.1.0", "v-org-tree": "^1.0.6", "vue": "^2.5.10", "vue-i18n": "^7.8.0", "vue-router": "^3.0.1", "vuedraggable": "^2.16.0", "vuex": "^3.0.1", "wangeditor": "^4.7.15", "xlsx": "^0.13.3" }, "devDependencies": { "@vue/cli-plugin-babel": "^3.0.1", "@vue/cli-plugin-eslint": "^3.0.1", "@vue/cli-plugin-unit-mocha": "^3.0.1", "@vue/cli-service": "^3.0.1", "@vue/eslint-config-standard": "^3.0.0-beta.10", "@vue/test-utils": "^1.0.0-beta.10", "chai": "^4.1.2", "eslint-plugin-cypress": "^2.0.1", "less": "^2.7.3", "less-loader": "^4.0.5", "lint-staged": "^6.0.0", "mockjs": "^1.0.1-beta3", "qs": "^6.6.0", "vue-template-c
最新发布
04-09
<think>好的,我现在需要处理用户关于iview-admin 2.0.0项目的配置和依赖项的查询。首先,我得回忆一下iview-admin的基本信息。iView-Admin是基于Vue.js和iView UI框架的后台管理系统模板,常用于快速开发企业级应用。用户提到版本2.0.0,可能需要确认该版本对应的依赖版本,比如VueiView、Webpack等。 接下来,我需要查找iview-admin 2.0.0的官方文档或者GitHub仓库,获取其package.json中的依赖项信息。通常,这类项目的依赖包括核心库如VueVue Router、Vuex,以及构建工具如Webpack、Babel。此外,UI框架iView的版本也需要确认,因为不同版本的iView可能对应不同的配置方式。 用户可能还想知道如何配置项目,比如如何修改主题、配置路由、状态管理等。因此,我需要整理出常见的配置文件和步骤,例如config目录下的dev.env.js和prod.env.js用于环境变量,vue.config.js用于自定义Webpack配置。另外,路由配置可能在src/router/index.js中,状态管理在src/store目录下。 同时,需要注意版本兼容性问题。比如,Vue 2.x与Vue 3.x的语法差异较大,iView-Admin 2.0.0可能依赖于Vue 2.x版本。如果用户使用的依赖版本过新,可能会引发兼容性问题,需要提醒用户注意版本匹配。 还要考虑构建和启动命令,通常这类项目使用npm run dev启动开发服务器,npm run build进行生产构建。可能还需要安装依赖时的注意事项,比如使用npm install或yarn安装所有依赖包。 最后,用户可能会遇到配置问题,比如如何自定义主题颜色或添加插件,这时候需要指导用户修改对应的配置文件或安装额外依赖。例如,iView的主题可以通过引入自定义的less变量文件来实现。 总结一下,我需要分步骤说明iview-admin 2.0.0的主要配置文件和依赖项版本,以及常见的配置方法和注意事项,确保用户能够顺利配置和运行项目。</think>### iview-admin 2.0.0 项目配置与依赖项解析 #### 一、核心依赖项版本 iview-admin 2.0.0 基于以下技术栈构建: 1. **Vue 2.x**: 基础框架 2. **iView UI 3.x**: 界面组件库(注意:iview 3.x 对应品牌名称为`View UI`) 3. **Webpack 4.x**: 构建工具 4. **Vue-cli 3.x**: 脚手架工具[^1] 具体版本范围参考`package.json`: ```json { "dependencies": { "vue": "^2.6.11", "view-design": "^4.0.0", // iview 4.0版本更名 "vue-router": "^3.2.0", "vuex": "^3.4.0" }, "devDependencies": { "@vue/cli-service": "^4.5.0", "webpack": "^4.44.2" } } ``` #### 二、关键配置文件 1. **环境配置**(位于`config/`目录) - `dev.env.js` 开发环境变量 - `prod.env.js` 生产环境变量 ```javascript // dev.env.js 示例 module.exports = { NODE_ENV: '"development"', API_BASE_URL: '"http://localhost:8080/api"' } ``` 2. **Vue 自定义配置**(`vue.config.js`) ```javascript module.exports = { devServer: { port: 8000, proxy: { '/api': { target: 'http://backend-service', ws: true } } }, chainWebpack: config => { config.plugin('define').tap(args => { args[0]['process.env'].VERSION = JSON.stringify(require('./package.json').version) return args }) } } ``` #### 三、功能模块配置 1. **路由配置**(`src/router/index.js`) ```javascript export default new Router({ routes: [ { path: '/dashboard', name: 'Dashboard', component: () => import('@/views/dashboard'), meta: { requiresAuth: true } } ] }) ``` 2. **状态管理**(`src/store/modules/`) ```javascript // user.js 示例 const user = { state: { token: localStorage.getItem('token') }, mutations: { SET_TOKEN(state, token) { state.token = token } } } ``` #### 四、版本兼容性注意事项 1. **Node.js 版本**: 推荐 v12.x LTS 版本 2. **VueView UI 版本绑定**: - View UI 4.x 仅支持 Vue 2.x - Vue 3.x 需要迁移至最新的 View UI Pro #### 五、项目启动命令 ```bash # 安装依赖 npm install --registry=https://registry.npm.taobao.org # 开发模式 npm run serve # 生产构建 npm run build # 代码规范检查 npm run lint ``` #### 六、自定义主题配置 1. 创建`src/styles/custom.less`: ```less @primary-color: #1890ff; // 全局主色 @menu-dark-bg: #001529; // 暗色菜单背景 ``` 2. 在`vue.config.js`中注入变量: ```javascript module.exports = { css: { loaderOptions: { less: { additionalData: `@import "@/styles/custom.less";` } } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值