一、Vue树形表格example.gif

官方文档

安装依赖

  1. yarn add vue-table-with-tree-grid
  1. npm i vue-table-with-tree-grid -S

使用

  1. import Vue from 'vue'
  2. import ZkTable from 'vue-table-with-tree-grid'
  3. Vue.use(ZkTable)

Or

  1. import Vue from 'vue'
  2. import ZkTable from 'vue-table-with-tree-grid'
  3. Vue.component(ZkTable.name, ZkTable)

示例:

  1. import TrreTable from 'vue-table-with-tree-grid'
  2. Vue.component('tree-table',TrreTable)

二、富文本编辑器

官方文档

安装

  1. yarn add vue-quill-editor

引入注册

  1. import Vue from 'vue'
  2. import VueQuillEditor from 'vue-quill-editor'
  3. // require styles
  4. import 'quill/dist/quill.core.css'
  5. import 'quill/dist/quill.snow.css'
  6. import 'quill/dist/quill.bubble.css'
  7. Vue.use(VueQuillEditor, /* { default global options } */)

客户端使用

  1. <template>
  2. <!-- bidirectional data binding(双向数据绑定) -->
  3. <quill-editor v-model="content"
  4. ref="myQuillEditor"
  5. :options="editorOption"
  6. @blur="onEditorBlur($event)"
  7. @focus="onEditorFocus($event)"
  8. @ready="onEditorReady($event)">
  9. </quill-editor>
  10. <!-- Or manually control the data synchronization(或手动控制数据流) -->
  11. <quill-editor :content="content"
  12. :options="editorOption"
  13. @change="onEditorChange($event)">
  14. </quill-editor>
  15. </template>
  16. <script>
  17. // you can also register quill modules in the component
  18. import Quill from 'quill'
  19. import { someModule } from '../yourModulePath/someQuillModule.js'
  20. Quill.register('modules/someModule', someModule)
  21. export default {
  22. data () {
  23. return {
  24. content: '<h2>I am Example</h2>',
  25. editorOption: {
  26. // some quill options
  27. }
  28. }
  29. },
  30. // manually control the data synchronization
  31. // 如果需要手动控制数据同步,父组件需要显式地处理changed事件
  32. methods: {
  33. onEditorBlur(quill) {
  34. console.log('editor blur!', quill)
  35. },
  36. onEditorFocus(quill) {
  37. console.log('editor focus!', quill)
  38. },
  39. onEditorReady(quill) {
  40. console.log('editor ready!', quill)
  41. },
  42. onEditorChange({ quill, html, text }) {
  43. console.log('editor change!', quill, html, text)
  44. this.content = html
  45. }
  46. },
  47. computed: {
  48. editor() {
  49. return this.$refs.myQuillEditor.quill
  50. }
  51. },
  52. mounted() {
  53. console.log('this is current quill instance object', this.editor)
  54. }
  55. }
  56. </script>

四、Echarts

官方文档

安装

  1. yarn add echarts

导入

局部组件

  1. import echarts from "echarts";
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ECharts</title>
  6. <!-- 引入 echarts.js -->
  7. <script src="echarts.min.js"></script>
  8. </head>
  9. <body>
  10. <!-- ECharts准备一个具备大小(宽高)的Dom -->
  11. <div id="main" style="width: 600px;height:400px;"></div>
  12. <script type="text/javascript">
  13. // 基于准备好的dom,初始化echarts实例
  14. var myChart = echarts.init(document.getElementById('main'));
  15. // 指定图表的配置项和数据
  16. var option = {
  17. title: {
  18. text: 'ECharts 入门示例'
  19. },
  20. tooltip: {},
  21. legend: {
  22. data:['销量']
  23. },
  24. xAxis: {
  25. data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
  26. },
  27. yAxis: {},
  28. series: [{
  29. name: '销量',
  30. type: 'bar',
  31. data: [5, 20, 36, 10, 10, 20]
  32. }]
  33. };
  34. // 使用刚指定的配置项和数据显示图表。
  35. myChart.setOption(option);
  36. </script>
  37. </body>
  38. </html>

五、nprogress进度条

官方文档

安装

  1. yarn add nprogress

使用

在main.js文件中

  1. //导入NProgress包对应的JS和css
  2. import NProgress from 'nprogress'
  3. import 'nprogress/nprogress.css'
  4. /* 配置请求的根路径 */
  5. axios.defaults.baseURL = 'http://192.168.14.42:8888/api/private/v1/'
  6. //在request拦截器中,展示进度条 NProgress.start()
  7. axios.interceptors.request.use(config=>{
  8. NProgress.start()
  9. config.headers.Authorization = window.sessionStorage.getItem('token')
  10. return config
  11. })
  12. //在response拦截器中,隐藏进度条 NProgress.done()
  13. axios.interceptors.response.use(config=>{
  14. NProgress.done()
  15. return config
  16. })
  17. Vue.prototype.axios = axios

六、select选择器

选择器详解

6-1 常规选择

绑定ID,根据类名获取

  1. <el-form-item label="所属医院">
  2. <el-select v-model="dataForm.hospitalId" clearable>
  3. <el-option
  4. v-for="item in hospitalList"
  5. :key="item.id"
  6. :label="item.hospitalName"
  7. :value="item.id"
  8. ></el-option>
  9. </el-select>
  10. </el-form-item>

image.png

6-2 获取label属性

  1. categoryList:[
  2. {
  3. categoryName:"***",
  4. categoryId:123456
  5. }
  6. ]

image.png
image.png

6-3 选择器带分页

参考文档
image.png image.png

6-3-1 组件封装

  1. <template>
  2. <el-row>
  3. <el-col>
  4. <el-select
  5. v-model="copyValue"
  6. filterable
  7. clearable
  8. :placeholder="place"
  9. @change="updateValue"
  10. >
  11. <el-option
  12. v-for="item in dataList"
  13. :key="item.value"
  14. :label="item[labelKey]"
  15. :value="item[valueKey]"
  16. >
  17. </el-option>
  18. <el-col>
  19. <div style="float: right; ">
  20. <el-pagination
  21. @current-change="handleCurrentChange"
  22. :current-page="pageInfo.page"
  23. :page-size="pageInfo.limit"
  24. layout="total, prev, pager, next"
  25. :total="pageInfo.total"
  26. >
  27. </el-pagination>
  28. </div>
  29. </el-col>
  30. </el-select>
  31. </el-col>
  32. </el-row>
  33. </template>
  34. <script>
  35. export default {
  36. name: "NewPageSelect",
  37. props: {
  38. //绑定值
  39. value: String,
  40. //下拉列表
  41. dataList: Array,
  42. //option的label在列表中对应的key
  43. labelKey: String,
  44. //option的value在列表中对应的key
  45. valueKey: String,
  46. //分页信息
  47. pageInfo: Object,
  48. place: String,
  49. },
  50. watch: {
  51. value: {
  52. handler: function (val) {
  53. this.copyValue = val;
  54. },
  55. deep: true,
  56. },
  57. },
  58. methods: {
  59. //更新值
  60. updateValue() {
  61. this.$emit("update:value", this.copyValue);
  62. },
  63. //翻页
  64. handleCurrentChange(val) {
  65. this.$emit("selectPageChange", val);
  66. },
  67. },
  68. data() {
  69. return {
  70. copyValue: this.value,
  71. };
  72. },
  73. };
  74. </script>
  75. <style scoped>
  76. </style>

6-3-2 父组件中使用

  1. <newPageSelect
  2. class="filter-item"
  3. style="width: 150px; margin-right: 20px"
  4. :value.sync="listQuery.userId"
  5. @selectPageChange="brandUserListSearch"
  6. :valueKey="'id'"
  7. :labelKey="'nickname'"
  8. :pageInfo="brandUserInfo"
  9. :dataList="brandUserList"
  10. :place="'品牌商'"
  11. >
  12. </newPageSelect>
  13. import NewPageSelect from "@/components/NewPageSelect";
  14. data(){
  15. return{
  16. brandUserInfo: {
  17. page: 1,
  18. limit: 5,
  19. total: 0,
  20. userIdentity: 1,
  21. },
  22. copyValue: this.value,
  23. brandUserList: [],
  24. }
  25. }
  26. props: {
  27. value: String,
  28. },
  29. watch: {
  30. //监听copyValue值变化
  31. copyValue: {
  32. handler(newV, oldV) {
  33. this.$emit("update:value", this.copyValue);
  34. },
  35. deep: true,
  36. },
  37. },
  38. created() {
  39. this.getList();
  40. this.brandUserListSearch();
  41. },
  42. //父实例查询
  43. brandUserListSearch(val) {
  44. userList(this.brandUserInfo).then((res) => {
  45. this.brandUserList = res.data.data.list;
  46. this.brandUserInfo.total = parseInt(res.data.data.total);
  47. });
  48. this.brandUserInfo.page = val;
  49. },

七、区域选择器

  1. <el-cascader
  2. ref="loactionCascaderRef"
  3. v-model="filter.location_code"
  4. :placeholder="$t('userlist.region')"
  5. :options="regions"
  6. clearable
  7. :props="{ checkStrictly: true }"
  8. @change="getUserList(true)"
  9. />

1、watch监听

  1. watch: {
  2. filterLocation(nV, oV) {
  3. if (this.$refs.loactionCascaderRef) {
  4. this.$refs.loactionCascaderRef.dropDownVisible = false
  5. }
  6. }
  7. },

2、引入regions

  1. import regions from '@/mixins/regions'
  2. mixins: [regions],

3.封装调用

1.api/common.js

  1. import request from '@/utils/request'
  2. export function regions() {
  3. return request({
  4. url: '/mock/constant/regions',
  5. method: 'get'
  6. })
  7. }

2.store/modules/common.js

  1. import { regions } from '@/api/common'
  2. const common = {
  3. state: {
  4. regions: []
  5. },
  6. mutations: {
  7. SET_REGIONS: (state, regions) => {
  8. state.regions = regions
  9. }
  10. },
  11. actions: {
  12. GetRegions({ commit }) {
  13. return new Promise((resolve, reject) => {
  14. regions()
  15. .then(res => {
  16. const regions = res.data
  17. commit('SET_REGIONS', regions)
  18. resolve(regions)
  19. })
  20. .catch(err => {
  21. reject(err)
  22. })
  23. })
  24. }
  25. }
  26. }
  27. export default common

3.store/getters.js

  1. const getters = {
  2. sidebar: state => state.app.sidebar,
  3. language: state => state.app.language,
  4. size: state => state.app.size,
  5. device: state => state.app.device,
  6. visitedViews: state => state.tagsView.visitedViews,
  7. cachedViews: state => state.tagsView.cachedViews,
  8. token: state => state.user.token,
  9. avatar: state => state.user.avatar,
  10. name: state => state.user.name,
  11. introduction: state => state.user.introduction,
  12. status: state => state.user.status,
  13. roles: state => state.user.roles,
  14. setting: state => state.user.setting,
  15. permission_routes: state => state.permission.routes,
  16. addRoutes: state => state.permission.addRoutes,
  17. regions: state => state.common.regions
  18. }
  19. export default getters

4.store/index.js

  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import app from './modules/app'
  4. import permission from './modules/permission'
  5. import tagsView from './modules/tagsView'
  6. import user from './modules/user'
  7. import common from './modules/common'
  8. import getters from './getters'
  9. Vue.use(Vuex)
  10. const store = new Vuex.Store({
  11. modules: {
  12. app,
  13. permission,
  14. tagsView,
  15. user,
  16. common
  17. },
  18. getters
  19. })
  20. export default store

5.mixins/regions.js

  1. export default {
  2. data() {
  3. return {
  4. regions: []
  5. }
  6. },
  7. created() {
  8. const regions = this.$store.getters.regions
  9. if (regions && regions.length) {
  10. this.regions = regions
  11. } else {
  12. this.$store
  13. .dispatch('GetRegions')
  14. .then(res => {
  15. this.regions = res
  16. })
  17. .catch(err => {
  18. console.log(err)
  19. })
  20. }
  21. }
  22. }

4.效果

image.png

八、侧边栏得自定义修改

image.png

结构层

  1. <el-scrollbar wrap-class="scrollbar-wrapper">
  2. <div class="logo">
  3. <img class="logo_img" src="../../../../../images/便医精查logo.png" alt />
  4. <div>便医精查</div>
  5. </div>
  6. <el-menu
  7. :show-timeout="200"
  8. :default-active="$route.path"
  9. :collapse="isCollapse"
  10. mode="vertical"
  11. class="el-menu-vertical-demo"
  12. >
  13. <sidebar-item
  14. v-for="route in permission_routers"
  15. :key="route.path"
  16. :item="route"
  17. :base-path="route.path"
  18. />
  19. </el-menu>
  20. </el-scrollbar>

样式层

  1. .logo {
  2. text-align: center;
  3. margin: 50px 0;
  4. font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  5. font-weight: bolder;
  6. }
  7. .logo_img {
  8. width: 50px;
  9. height: 50px;
  10. margin-bottom: 10px;
  11. }
  12. .el-menu {
  13. background-color: #f1f1f6;
  14. text-align: center;
  15. }
  16. .el-menu-item.is-active {
  17. color: #fff !important;
  18. background-color: #7e7eff !important;
  19. }
  20. .el-menu-item {
  21. background-color: #f1f1f6;
  22. color: #49497e;
  23. height: 40px;
  24. line-height: 40px;
  25. margin-bottom: 20px;
  26. width: 170px;
  27. border-radius: 4px;
  28. font-size: 16px;
  29. margin: 10px auto;
  30. }
  31. #app .sidebar-container .submenu-title-noDropdown:hover,
  32. #app .sidebar-container .el-submenu__title:hover {
  33. background-color: #7e7eff !important;
  34. color: #fff !important;
  35. }
  36. #app .sidebar-container {
  37. font-size: 18px;
  38. }
  39. #app .sidebar-container .is-active > .el-submenu__title {
  40. color: #7e7eff !important;
  41. }
  42. #app .sidebar-container .nest-menu .el-submenu > .el-submenu__title,
  43. #app .sidebar-container .el-submenu .el-menu-item {
  44. background-color: #f1f1f6 !important;
  45. height: 40px;
  46. line-height: 40px;
  47. margin-bottom: 20px;
  48. width: 170px;
  49. border-radius: 4px;
  50. font-size: 16px;
  51. margin: 10px auto;
  52. }
  53. #app .sidebar-container .el-submenu .is-active {
  54. color: #fff !important;
  55. background-color: #7e7eff !important;
  56. }
  57. .el-submenu__title {
  58. border-radius: 4px;
  59. height: 40px;
  60. line-height: 40px;
  61. width: 170px;
  62. font-size: 16px;
  63. color: #49497e;
  64. margin: 10px auto;
  65. padding: 0 20px;
  66. list-style: none;
  67. cursor: pointer;
  68. position: relative;
  69. -webkit-transition: border-color 0.3s, background-color 0.3s, color 0.3s;
  70. transition: border-color 0.3s, background-color 0.3s, color 0.3s;
  71. -webkit-box-sizing: border-box;
  72. box-sizing: border-box;
  73. white-space: nowrap;
  74. }
  75. #app .sidebar-container .el-submenu .el-menu-item:hover {
  76. background-color: #7e7eff !important;
  77. color: #fff !important;
  78. }

效果图

image.png

九、table表格中放大图片

9-1 单张图片

  1. <el-table-column align="center" property="backCardImg" label="身份证反面照">
  2. <template slot-scope="scope">
  3. <el-popover placement="bottom" trigger="click">
  4. <!--trigger属性值:hover、click、focus 和 manual-->
  5. <a :href="scope.row.backCardImg" target="_blank" title="查看最大化图片">
  6. <img :src="scope.row.backCardImg" style="width: 560px;height: 560px" />
  7. </a>
  8. <img
  9. slot="reference"
  10. :src="scope.row.backCardImg"
  11. style="width: 80px;height: 80px; cursor:pointer"
  12. />
  13. </el-popover>
  14. </template>
  15. </el-table-column>

9-2 多张图片

  1. <el-table-column label="小票图片" align="center">
  2. <template slot-scope="scope">
  3. <span v-for="(item,index) in scope.row.smallTicketImg" :key="index">
  4. <el-popover placement="left" trigger="click" width="500">
  5. <img :src="item" width="100%" />
  6. <img
  7. slot="reference"
  8. :src="item"
  9. :alt="item"
  10. style="max-height: 80px;max-width: 80px; padding: 3px"
  11. />
  12. </el-popover>
  13. </span>
  14. </template>
  15. </el-table-column>

十、关于时间选择器

官网

10-1 日期格式

使用format指定输入框的格式;使用value-format指定绑定值的格式。

  1. <el-form-item label="开始时间" prop="startTime">
  2. <el-date-picker
  3. v-model="dataForm.startTime"
  4. value-format="yyyy-MM-dd hh:mm:ss"
  5. type="datetime"
  6. placeholder="选择日期时间"
  7. ></el-date-picker>
  8. </el-form-item>