首页 > 其他分享 >从零开始使用vue2+element搭建后台管理系统(主页)

从零开始使用vue2+element搭建后台管理系统(主页)

时间:2023-09-15 13:55:05浏览次数:42  
标签:flex false name bottom element 从零开始 vue2 height margin

登录后,应有一个主页,可以展示当前用户的一些信息,例如上次登录时间地点、修改手机号、重置密码等简单功能,如图:

 

 首先在views下新建HomeView.vue文件:

<template>
  <el-row>
    <el-col :span="24">
      <!-- user卡片 -->
      <el-card>
        <div class="user">
          <img :src="avatar" alt="avatar" />
          <div class="userInfo">
            <p div class="name">{{ name }}</p>
            <p div class="access">超级管理员</p>
          </div>
        </div>
        <div class="loginInfo">
          <el-descriptions class="margin-top" :column="1" border>
            <el-descriptions-item>
              <template slot="label">
                <i class="el-icon-user"></i>
                上次登陆
              </template>
              厦门
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <i class="el-icon-mobile-phone"></i>
                手机号码
              </template>
              {{ phone }}
              <BindPhone :user-name="'12345'" @reset="reset">
                <template v-slot="{ showDialog }">
                  <i
                    class="el-icon-edit"
                    style="cursor: pointer; margin-left: 8px"
                    @click="showDialog"
                  ></i
                ></template>
              </BindPhone>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <i class="el-icon-edit-outline"></i>
                其他操作
              </template>
              <el-button size="mini" @click="visible = true"
                >重置密码</el-button
              >
            </el-descriptions-item>
          </el-descriptions>
        </div>
      </el-card>
    </el-col>
    <el-dialog
      :visible.sync="visible"
      width="480px"
      center
      append-to-body
      title="重置密码"
    >
      <p>账号: {{ name }}</p>
      <p>{{ text }}</p>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="handleOk">确 定</el-button>
      </span>
    </el-dialog>
  </el-row>
</template>

<script>
import BindPhone from "@/components/BindPhone.vue";
import { getUserInfo } from "@/utils/auth";
export default {
  data() {
    return {
      visible: false,
      phone: "15788889999",
      text: "将重置登录密码为123456,此操作不可逆,请确认后执行",
    };
  },
  computed: {
    avatar() {
      return this.$store.state.user.avatar || getUserInfo("avatar");
    },
    name() {
      return this.$store.state.user.name || getUserInfo("name");
    },
  },
  mounted() {},
  methods: {
    reset() {
      // v
    },
    handleOk() {
      this.$alert(`账号${this.name} 密码已重置为123456`, "操作成功", {
        confirmButtonText: "确定",
        callback: () => {
          this.visible = false;
          this.$emit("getDetail");
        },
      });
    },
  },
  components: {
    BindPhone,
  },
};
</script>

<style lang="scss" scoped>
.user {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid #ccc;

  img {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    margin-right: 40px;
  }

  .userInfo {
    .name {
      font-size: 32px;
      margin-bottom: 10px;
    }

    .access {
      color: #999999;
    }
  }
}

.loginInfo {
  p {
    line-height: 28px;
    font-size: 14px;
    color: #999999;
    span {
      color: #666666;
      margin-left: 36px;
      margin-right: 8px;
    }
  }
}

.num {
  display: flex;
  // 要换行
  flex-wrap: wrap;
  // 从头到尾均匀排列
  justify-content: space-between;
  margin-left: 20px;

  .el-card {
    width: 32%;
    margin-bottom: 20px;

    .icon {
      width: 80px;
      height: 80px;
      line-height: 80px;
      text-align: center;
      font-size: 30px;
      color: #fff;
    }

    .details {
      // 竖着排且居中
      display: flex;
      flex-direction: column;
      justify-content: center;

      margin-left: 15px;

      .price {
        font-size: 30px;
        margin-bottom: 10px;
        line-height: 30px;
        height: 30px;
      }

      .desc {
        font-size: 14px;
        color: #999;
        text-align: center;
      }
    }
  }
}

.graph {
  display: flex;
  // 两个靠边
  justify-content: space-between;
  margin-top: 20px;

  .el-card {
    width: 49%;
  }
}
</style>

  

手机改绑组件:

<template>
  <span>
    <slot :show-dialog="showDialog"
      ><el-button size="mini" @click="showDialog" style="margin-left: 8px">{{
        btnText
      }}</el-button></slot
    >
    <el-dialog :visible.sync="visible" width="480px" center append-to-body>
      <el-form
        :model="bindForm"
        :rules="rules"
        ref="bindForm"
        label-position="right"
      >
        <el-form-item
          label="新手机号"
          prop="newPhone"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="bindForm.newPhone"
            autocomplete="off"
            maxlength="11"
          >
            <template slot="append"
              ><el-button size="mini" :disabled="disabled" @click="getCode">{{
                codeBtnText
              }}</el-button></template
            >
          </el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="code" :label-width="formLabelWidth">
          <el-input
            v-model="bindForm.code"
            autocomplete="off"
            maxlength="6"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="handleOk('bindForm')"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </span>
</template>
<script>
export default {
  name: "BindPhone",
  props: {
    userName: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      btnText: "手机改绑",
      visible: false,
      disabled: false,
      codeBtnText: "获取验证码",
      bindForm: {
        newPhone: "",
        code: "",
      },
      formLabelWidth: "80px",
      rules: {
        newPhone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            required: true,
            pattern:
              /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/,
            message: "请输入正确的手机号",
            trigger: "blur",
          },
        ],
        code: [{ required: true, message: "请输入验证码", trigger: "blur" }],
      },
    };
  },
  computed: {},
  mounted() {},
  methods: {
    showDialog() {
      this.visible = true;
    },
    // 验证码倒数60秒
    validBtnText() {
      let time = 60;
      let timer = setInterval(() => {
        if (time === 0) {
          clearInterval(timer);
          this.codeBtnText = "获取验证码";
          this.disabled = false;
        } else {
          this.disabled = true;
          this.codeBtnText = time + "秒后重新获取";
          time -= 1;
        }
      }, 1000);
    },
    getCode() {
      this.$refs["bindForm"].validateField("newPhone", (err) => {
        if (err) {
          return;
        } else {
          this.validBtnText();
        }
      });
    },
    handleOk(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          this.visible = false;
          this.$emit("reset");
        }
      });
    },
  },
};
</script>

  

(是的依旧没有接口)

其中包括了获取验证码的倒数功能,还是比较常用的。

 

标签:flex,false,name,bottom,element,从零开始,vue2,height,margin
From: https://www.cnblogs.com/nangras/p/17704862.html

相关文章

  • element - 多表单验证必填
    方式1、该方法原文地址:https://blog.csdn.net/yprufeng/article/details/113052798方式2、//封装的js文件exportfunctionvalidateForms(formRefs){letobjectList=[];letresults=formRefs.map(formRef=>newPromise((resolve,reject)=>{......
  • 关于element-plus框架一些样式的修改
    一、关于使用element框架一些测试建议覆盖的样式1.取消按钮的focus效果(1)css样式覆盖//element按钮部分伪类样式覆盖//用于覆盖element按钮focus的样式.el-button:not(.is-link):not(.is-text):not(.is-disabled):not(.is-has-bg):focus{color:var(--el-button-text-......
  • vue2.0 表单验证明明有值却提示错误
    明明有值却总是提示为空我的解决方法时将number转为字符串验证方法如图:(验证只可以输入数字)赋值时转为字符串: ......
  • vue3 elementplus 列表中添加排序功能,移动的时候修改背景色
    <el-tablesize="medium":border="true":data="branchTableData":row-style="changeColor":stripe=falsestyle="width:100%;">......
  • 从零开始使用vue2+element搭建后台管理系统(实现按钮权限控制)
    思路:登录后请求用户信息接口,后端返回用户信息中包括权限数组,数据格式belike: 前端对用户信息进行存储(对没错又是假接口)://获取用户信息asyncgetUserInfo(mobile){try{this.loading=true;constres=awaitgetInfo(mobile);......
  • vue2实现pc端自适应分辨率
    思路:使用lib-flexible结合postcss-pxtorem实现第一步在项目utils下建立flexible.js文件(直接下载则不用新建该文件)第二部复制以下代码到刚建好的文件中或者直接yarninstalllib-flexible-pc-y//基于libflexible用来适配pc端(function(win,lib){ vardoc=win.docu......
  • 如何将element-ui中的tab组件默认展示的tab标签数量改掉?
    要将ElementUI中的Tab组件默认展示的标签数量更改,可以使用tab-list属性设置。tab-list属性用于控制默认展示的标签数量。以下是修改Tab组件默认展示标签数量的示例代码:<template><el-tabsv-model="activeTab":tab-list="tabList"><el-tab-panev-for="tabint......
  • 从零开始使用vue2+element搭建后台管理系统(实现导出excel表格的功能)
    首先参阅了以下文档:https://panjiachen.gitee.io/vue-element-admin-site/zh/feature/component/excel.html#excel-%E5%AF%BC%E5%87%BAhttps://blog.csdn.net/weixin_42028153/article/details/124804841核心思想:抄一下vue-element-admin这个很棒的开源集成后台管理系统中所提......
  • VUE2教程-基础-Class 与 Style 绑定
    Class与Style绑定操作元素的class列表和内联样式是数据绑定的一个常见需求。因为它们都是attribute,所以我们可以用 v-bind 处理它们:只需要通过表达式计算出字符串结果即可。不过,字符串拼接麻烦且易错。因此,在将 v-bind 用于 class 和 style 时,Vue.js做了专门的增强......
  • VUE2基础-Vue实例
    Vue实例创建一个Vue实例 每个Vue应用都是通过用 Vue 函数创建一个新的 Vue实例开始的:varvm=newVue({//选项})虽然没有完全遵循 MVVM模型,但是Vue的设计也受到了它的启发。因此在文档中经常会使用 vm (ViewModel的缩写)这个变量名表示Vue实例。当创建......