卡片风格与列表风格的切换

一、背景

  • 在前端显示页面中,我们有时候喜欢用卡片风格,比如说这样的:

 

  • 有时候喜欢用列表风格,比如说这样的:

二、卡片风格

  • 将信息通过el-card来渲染出卡片风格的页面
<el-row v-if="cardType" style="height:  calc(100% - 70px);">
        <el-col
          v-for="item in dataList"
          :key="item.id"
          style="margin-top: 20px;padding-left: 8px;padding-right: 8px"
          :xs="24" :sm="12" :lg="6"
        >
          <el-card>
            <div slot="header" class="clearfix">
              <i class="el-icon-tickets" /><span style="margin-left: 5px">{{
                item.name
              }}</span>
              <div
                style="display: inline-block; float: right; cursor: pointer"
                @click="handleUpdate(item)"
                v-hasPermi="['workmanship:processConfig:update']"
              >
                <el-tooltip effect="dark" content="修改" placement="top">
                  <i class="el-icon-edit-outline" style="margin-left: 15px" />
                </el-tooltip>
              </div>
            </div>
            <div>
              <ul class="role-info">
                  <li>
                    <div class="role-left">流程编号:{{ item.id }}</div>
                  </li>
                <li>
                  <div class="role-left">归属部门:{{ item.deptName }}</div>
                </li>
                <li>
                  <div class="role-left">
                    创建时间{{ parseTime(item.createTime) }}
                  </div>
                </li>
                <li>
                  <div class="role-left">
                    备注:{{ item.remark }}
                  </div>
                </li>
              </ul>
            </div>
            <el-divider></el-divider>
            <div
              style="display: inline-block; float: left; cursor: pointer;margin-bottom: 10px;"
              @click="doConfig(item)"
              v-hasPermi="['workmanship:processConfig:config']"
            >
              <el-tooltip effect="dark" content="流程配置" placement="bottom">
                <i class="el-icon-s-tools" />
              </el-tooltip>
            </div>
            <div
              style="display: inline-block; float: left; cursor: pointer;margin-left: 10px;margin-bottom: 10px;"
              @click="doShowViem(item)"
              v-hasPermi="['workmanship:processConfig:show']"
            >
              <el-tooltip effect="dark" content="流程查看" placement="bottom">
                <i class="el-icon-view" />
              </el-tooltip>
            </div>
            <div
              style="display: inline-block; float: right; cursor: pointer;margin-bottom: 10px;"
              @click="handleDelete(item)"
              v-hasPermi="['workmanship:processConfig:remove']"
            >
              <el-tooltip effect="dark" content="删除" placement="bottom">
                <i class="el-icon-delete" style="margin-left: 15px" />
              </el-tooltip>
            </div>
          </el-card>
        </el-col>
      </el-row>

      <paginations
        v-if="cardType"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

 

三、列表风格

  • 将信息通过el-table来渲染出列表风格的页面
<el-table v-loading="loading"
                v-if="!cardType"
                :data="dataList"
                border
                stripe
                :header-cell-style="{backgroundColor:'#A0CCF3',color:'#000000'}">
        <el-table-column  label="流程编号" align="left" prop="id"/>
        <el-table-column  label="流程名称" align="left" prop="name"/>
        <el-table-column  label="归属部门" align="left" prop="deptName"/>
        <el-table-column  label="创建日期" align="left" prop="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime)}}</span>
          </template>
        </el-table-column>
        <el-table-column  label="备注" align="left" prop="remark" :show-overflow-tooltip="true"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
            size="mini"
            type="text"
            v-hasPermi="['workmanship:processConfig:config']">
              <router-link :to="{path:'/workmanship/process/config',query: {id: scope.row.id,deptCode: scope.row.deptCode}}" class="link-type">
                <span style="color: #409EFF ">流程配置</span>
              </router-link>
            </el-button>
            <el-button
            size="mini"
            type="text"
            v-hasPermi="['workmanship:processConfig:show']">
              <router-link :to="{path:'/workmanship/process/show',query: {id: scope.row.id,deptCode: scope.row.deptCode}}" class="link-type">
                <span style="color: #409EFF ">流程查看</span>
              </router-link>
            </el-button>
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['workmanship:processConfig:update']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
              v-hasPermi="['workmanship:processConfig:remove']"
              class="mpc_del"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-if="!cardType"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

四、实现两种风格的切换

  • 增加一个切换按钮,并增加cardType变量,为true时显示卡片风格,为false时显示列表风格,用户点击此按钮可自由切换两种风格.
<el-form-item class="option-button">
        <el-button type="primary" size="mini" @click="toggle" v-if="!cardType">
          <el-button-context class-name="ic_apps" text="切换"/>
        </el-button>
        <el-button type="primary" size="mini" @click="toggle" v-if="cardType">
          <el-button-context class-name="ic_dehaze" text="切换"/>
        </el-button>
      </el-form-item>

五、页面全部源码

<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb16 mpc-section" >

      <el-col :span="1.5">
        <el-button type="primary" size="mini" @click="handleAdd" >
          <el-button-context class-name="fun-new" text="新增"/>
        </el-button>
      </el-col>
    </el-row>

    <el-form class="mpc-section" :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item prop="name">
        <el-input
          v-model="queryParams.name"
          clearable
          @keyup.enter.native="handleQuery"
          @clear="handleQuery"
        />
      </el-form-item>

      <el-form-item class="option-button">
        <el-button type="primary" size="mini" @click="handleQuery">
          <el-button-context class-name="fun-search" text="查询"/>
        </el-button>
        <el-button type="primary" size="mini" @click="toggle" v-if="!cardType">
          <el-button-context class-name="ic_apps" text="切换"/>
        </el-button>
        <el-button type="primary" size="mini" @click="toggle" v-if="cardType">
          <el-button-context class-name="ic_dehaze" text="切换"/>
        </el-button>
      </el-form-item>
      
      
    </el-form>

    <!-- 在el-table的外围添加一个div,包裹至pagination后面 -->
    <div :class="
          'mpc-table-section','mpc-table-normal','mpc-table-normal-nofuntion')">
      <el-table v-loading="loading"
                v-if="!cardType"
                :data="dataList"
                border
                stripe
                :header-cell-style="{backgroundColor:'#A0CCF3',color:'#000000'}">
        <el-table-column  label="编号" align="left" prop="id"/>
        <el-table-column  label="名称" align="left" prop="name"/>
        <el-table-column  label="归属部门" align="left" prop="deptName"/>
        <el-table-column  label="创建日期" align="left" prop="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime)}}</span>
          </template>
        </el-table-column>
        <el-table-column  label="备注" align="left" prop="remark" :show-overflow-tooltip="true"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
            size="mini"
            type="text">
              <router-link :to="{path:'/workmanship/process/config',query: {id: scope.row.id,deptCode: scope.row.deptCode}}" class="link-type">
                <span style="color: #409EFF ">流程配置</span>
              </router-link>
            </el-button>
            <el-button
            size="mini"
            type="text">
              <router-link :to="{path:'/workmanship/process/show',query: {id: scope.row.id,deptCode: scope.row.deptCode}}" class="link-type">
                <span style="color: #409EFF ">流程查看</span>
              </router-link>
            </el-button>
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
              class="mpc_del"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-if="!cardType"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      
      <el-row v-if="cardType" style="height:  calc(100% - 70px);">
        <el-col
          v-for="item in dataList"
          :key="item.id"
          style="margin-top: 20px;padding-left: 8px;padding-right: 8px"
          :xs="24" :sm="12" :lg="6"
        >
          <el-card>
            <div slot="header" class="clearfix">
              <i class="el-icon-tickets" /><span style="margin-left: 5px">{{
                item.name
              }}</span>
              <div
                style="display: inline-block; float: right; cursor: pointer"
                @click="handleUpdate(item)"
              >
                <el-tooltip effect="dark" content="修改" placement="top">
                  <i class="el-icon-edit-outline" style="margin-left: 15px" />
                </el-tooltip>
              </div>
            </div>
            <div>
              <ul class="role-info">
                  <li>
                    <div class="role-left">流程编号:{{ item.id }}</div>
                  </li>
                <li>
                  <div class="role-left">归属部门:{{ item.deptName }}</div>
                </li>
                <li>
                  <div class="role-left">
                    创建时间{{ parseTime(item.createTime) }}
                  </div>
                </li>
                <li>
                  <div class="role-left">
                    备注:{{ item.remark }}
                  </div>
                </li>
              </ul>
            </div>
            <el-divider></el-divider>
            <div
              style="display: inline-block; float: left; cursor: pointer;margin-bottom: 10px;"
              @click="doConfig(item)"
            >
              <el-tooltip effect="dark" content="配置" placement="bottom">
                <i class="el-icon-s-tools" />
              </el-tooltip>
            </div>
            <div
              style="display: inline-block; float: left; cursor: pointer;margin-left: 10px;margin-bottom: 10px;"
              @click="doShowViem(item)"
            >
              <el-tooltip effect="dark" content="查看" placement="bottom">
                <i class="el-icon-view" />
              </el-tooltip>
            </div>
            <div
              style="display: inline-block; float: right; cursor: pointer;margin-bottom: 10px;"
              @click="handleDelete(item)"
            >
              <el-tooltip effect="dark" content="删除" placement="bottom">
                <i class="el-icon-delete" style="margin-left: 15px" />
              </el-tooltip>
            </div>
          </el-card>
        </el-col>
      </el-row>

      <paginations
        v-if="cardType"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <el-dialog :title="title" :visible.sync="open" append-to-body :close-on-click-modal="false">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入名称"  :disabled="disableType"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="归属部门" prop="deptCode">
                <treeselect v-model="form.deptCode" :options="deptOptions" :normalizer="deptNormalizer" placeholder="请选择归属部门" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="备注" prop="remark" class="textarea_fix">
                <el-input v-model.trim="form.remark" type="textarea" rows="3" placeholder="请输入备注信息"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm" v-preventReClick="2000">保 存</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>

    </div>

  </div>

</template>

<script>
import { getInfos,save,getProject,update,del } from "@/api/workmanship/processConfig/config";
import { optionDeptApi,listDeptTreeApi,listDeptApi } from '@/api/system/organize/dept'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import ElButtonContext from '@/components/Mes/ElButtonContext'

export default {
  name: "processConfig",
  components: { ElButtonContext, Treeselect },
  data() {
    const isNum = (rule, value, callback) => {
      if (!Number(value)) {
        callback(new Error('请输入数字'))
      }else{
        callback()
      }
    }
    return {
      cardType:false,
      disableType:false,//输入框默认可输入
      multiple: true,   // 非多个禁用(批量删除)
      total: 0,         // 总条数
      queryParams:{     // 查询条件
        pageNum: 1,
        pageSize: 20,
        workmanshipName:undefined,
        beginTime:undefined,
        endTime:undefined
      },
      // 部门树选项
      deptOptions: [],
      dataList:[],     // 显示数据(主页面)
      dateRange: [],   // 查询日期范围
      showSearch: true,// 显示搜索条件
      title: "",       // 弹出层标题(新增修改)
      open: false,     // 是否显示弹出层(新增修改)
      form:{  },       // 表单(新增修改)
      submitLoading: false,
      loading:true,
      rules: {         // 表单校验(新增修改)
        name: [
          { required: true, message: "流程名称不能为空", trigger: "blur" },
          { min: 0, max: 100, message: "长度在 0 到 100 个字符" },
        ],
        deptCode:[
          { required: true, message: "部门编号不能为空", trigger: "blur" },
          { min: 0, max: 100, message: "长度在 0 到 50 个字符" },
        ],
        remark:[
          { min: 0, max: 200, message: "长度在 0 到 200 个字符" },
        ]
      },
    }
  },
  created() {
    this.getList();
    this.getOptions();
  },
  methods:{

    doConfig(item){
      this.$router.push({
          path: '/workmanship/process/config',
          query: {id: item.id,deptCode: item.deptCode}
        })
    },
    doShowViem(item){
      this.$router.push({
          path: '/workmanship/process/show',
          query: {id: item.id,deptCode: item.deptCode}
        })
    },
    toggle(){
      this.cardType = !this.cardType
      if(this.cardType){
        this.queryParams.pageSize = 8
        this.getList();
      }else{
        this.queryParams.pageSize = 20
        this.getList();
      }
    },
    
    /** 查询部门列表 */
    getOptions() {
      this.deptOptions = []
      listDeptTreeApi().then(response => {
        this.deptOptions = response.data
      })
    },
    
    /** 转换树数据结构 */
    deptNormalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.code,
        label: node.name,
        isDisabled: false,
        children: node.children
      }
    },
    // 表单重置(新增修改)
    reset() {
      this.form = {
        id: undefined,
        workmanshipName: undefined,
        workmanshipCode: undefined,
        remark: undefined,
      };
      this.resetForm("form");
    },
    //数据列表
    getList(){
      this.loading = true;
      this.queryParams.beginTime=this.dateRange !=null?this.dateRange[0]:null;
      this.queryParams.endTime=this.dateRange !=null?this.dateRange[1]:null;
      getInfos(this.queryParams).then(response => {
        if (response.rows.length == 0 && this.queryParams.pageNum > 1) {
          this.queryParams.pageNum = this.queryParams.pageNum - 1;
          this.total = response.total;
          this.getList();
        } else {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      })
    },
    //点击查询
    handleQuery(){
      this.queryParams.pageNum = 1;
      this.getList();
    },
    //点击新增
    handleAdd(){
      this.reset();// 表单重置(新增工艺)
      this.disableType=false;//input框可输入
      this.open = true;// 打开(新增工艺)模态框
      this.title = "新增工艺";//(新增修改模态框)动态标题
    },
    //点击批量删除
    handleDelete(row){
      const workmanshipIds = row.id || this.ids//获取选中数据的工艺id
      this.$confirm('是否确认删除选中的数据', "警告", {
        closeOnClickModal: false,
        confirmButtonText: "确定",
        cancelButtonText: "关闭",
        type: "warning"
      }).then(function() {
        return del(workmanshipIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(function() {});
    },
    //点击修改
    handleUpdate(row){
      this.reset();// 表单重置(修改工艺)
      this.form = row;
      this.open = true;
      this.title = "修改工艺";
    },
    //点击模态框提交
    submitForm(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            update(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            //新增接口数据
            save(this.form).then(response => {
              if (response.code === 200) {//返回code等于200时,新增成功
                this.msgSuccess("新增成功");//弹出新增成功模态框
                this.open = false;//关闭新增模态框
                this.getList();//刷新工艺列表数据
              }
            });
          }
        }
      })
    },
    //点击模态框取消
    cancel(){
      this.open = false;//关闭模态框(新增修改上传)
      this.attribute=false;
      this.reset();// 表单重置
      this.getList();
    }
  }
}
</script>

<style scoped>

</style>
<style scoped>
/deep/ .el-dialog__body {
  max-height: calc(100vh - 300px);
  padding: 24px 24px 24px 24px !important;
  margin-bottom: 0px;
  background-color: #FFFFFF;
  font-weight:lighter;
  overflow-y: auto;
}

</style>

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Android拟态风格是指在设计Android应用时使用的界面风格,它的目的是让应用看起来尽可能地像真实的物理设备。这种风格的代码可以使用Android框架中提供的各种布局和控件,如ActionBar、FloatingActionButton和CardView等。 举个例子,下面是一段使用Android拟态风格创建登录界面的代码: ``` <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/logo" android:layout_gravity="center_horizontal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/login_prompt" android:textSize="18sp" android:layout_marginTop="16dp" android:layout_gravity="center_horizontal" /> <EditText android:id="@+id/username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/username" android:inputType="text" android:layout_marginTop="16dp" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/password" android:inputType="textPassword" android:layout_marginTop="8dp" /> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/login" android:layout_marginTop="16dp" android:layout_gravity="center_horizontal" /> </LinearLayout> ``` 在这段代码中,我们使用了一个LinearLayout来垂直排列各个控件,并使用了ImageView、TextView、EditText和Button等控件来创建登录界面。 希望这对您有帮 ### 回答2: Android拟态风格是一种设计风格,强调简洁、直观和现代感。为了实现拟态风格,Android开发者可以通过以下几种方式来编写代码: 1. 使用Material Design库:Google在Android中提供了Material Design库,开发者可以使用其中的设计元素和样式来实现拟态风格。例如,可以使用Button组件的elevation属性来添加卡片效果,或者使用CardView组件创建卡片式的界面。 2. 使用阴影和淡化效果:拟态风格强调在视觉上给予元素一种漂浮的感觉。开发者可以通过为组件添加阴影效果来营造浮动的效果,并使用透明度来实现淡化效果。 3. 使用圆角和边框:拟态风格通常使用圆角和边框来创造柔和和现实感。开发者可以在代码中设置组件的圆角半径和边框样式,以实现拟态风格的效果。 4. 使用渐变和动画效果:在拟态风格中,渐变和动画效果可以增添元素的层次感和活力。开发者可以通过设置不同颜色的渐变背景来为组件添加层次感,或者使用动画效果来为元素添加交互和生动感。 总之,实现Android拟态风格代码需要使用Material Design库中的元素和样式,通过添加阴影、圆角、边框、渐变和动画效果来打造简洁、直观和现代感的用户界面。 ### 回答3: Android拟态风格是一种设计风格,旨在为用户提供更加直观、真实的用户界面体验。在编写代码时,我们可以采用一些技术和规范来实现这种风格。 首先,我们可以使用Android官方提供的Material Design库来实现拟态风格。这个库提供了一些预定义的组件和样式,我们可以直接在代码中使用。例如,通过导入Material Design库,在布局文件中使用`com.google.android.material.button.MaterialButton`组件,就可以使用拟态风格的按钮。 其次,为了实现更加真实的拟态效果,我们可以使用一些动画和过渡效果。比如,在用户点击按钮时,可以添加一个淡入淡出的动画,使按钮在被点击时产生反馈效果。我们也可以使用转场动画,在界面切换时实现平滑的过渡效果。 此外,拟态风格还强调使用明亮而鲜艳的颜色,以及最小化的阴影和边框效果。因此,在编写样式时,我们应该选择适合的颜色,并使用阴影和边框来增强拟态效果。 最后,代码的可读性和可维护性也非常重要。我们应该遵循良好的编码规范,使用有意义的变量和函数命名,以及模块化和可重用的代码结构。这样可以使我们的代码更易于理解和维护。 总之,通过使用Material Design库、添加动画和过渡效果、选择适合的颜色和使用阴影边框等技术,我们可以在Android应用中实现拟态风格的界面。编写拟态风格的代码需要注重细节和对用户体验的关注,以提供更加直观、真实的界面效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值