Commit 7c9d0b53 by 无尘

add: 增加好办后台公共 header 插件

parent 1575ecec
{
"presets": [
["env", { "modules": false }],
"stage-3"
]
}
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
.DS_Store
node_modules/
npm-debug.log
yarn-error.log
package-lock.json
# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
# 好办 office header
\ No newline at end of file
# 好办公共 header 插进
>>>HEAD
> A Vue.js vue-office-header Plugin
## Install
- 记得需要切换 公司源
- 换源: npm config set registry http://www.gicdev.com:7001/ 或者使用 nrm 切换
```shell
npm install @gic-test/vue-office-header -S
```
## how to use
```
// main.js
import vueOfficeHeader from '@gic-test/vue-office-header'
Vue.use(vueOfficeHeader)
// 使用页面
<vue-office-header :projectName="projectName" :collapseFlag="collapseFlag" @collapseTag="collapseTag" @toRouterView="toRouterView"></vue-office-header>
data() {
return {
// 可传参数
projectName: '', // 当前项目名
collapseFlag: false, // 折叠参数
// 路由菜单
// 修改由插件请求
}
}
methods: {
// 处理路由跳转
toRouterView(val) {
var that = this;
// 模拟检查数据
console.log(val);
//有两个参数
//{
// name:,
// path:
//}
that.$router.push({
path: val.path
})
},
// 折叠事件
collapseTag(val){
var that = this;
console.log(val);
}
},
```
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>vue-office-header</title>
</head>
<body>
<div id="app"></div>
<!-- <script src="/dist/build.js"></script> -->
<script src="/dist/vue-office-header.js"></script>
</body>
</html>
{
"name": "@gic-test/vue-office-header",
"description": "vue-office-header Plugin",
"author": "fairyly <498745097@qq.com>",
"version": "1.0.2",
"license": "MIT",
"private": false,
"main": "dist/vue-office-header.js",
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"axios": "^0.18.0",
"vue": "^2.5.11"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"file-loader": "^1.1.4",
"less": "^3.0.4",
"less-loader": "^4.1.0",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.6",
"vue-loader": "^13.0.5",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
}
}
<template>
<div id="app">
<vue-gic-header :projectName="projectName" :collapseFlag="collapseFlag" @collapseTag="collapseTag" @toRouterView="toRouterView"></vue-gic-header>
</div>
</template>
<script>
import vueGicHeader from './lib/vue-gic-header'
export default {
name: 'app',
data () {
return {
projectName: '', // 当前项目名
// headerRouterOptions: {
collapseFlag: false, // 折叠参数
// 路由菜单
// 修改由插件请求
// },
}
},
components: {
vueGicHeader
},
methods: {
// 处理路由跳转
toRouterView(val) {
var that = this;
// 模拟检查数据
// //有两个参数
//{
// name:,
// path:
//}
console.log(val);
that.$router.push({
path: val.path
})
},
// 折叠事件
collapseTag(val){
var that = this;
console.log(val);
}
}
}
</script>
<style lang="scss">
* {
margin: 0;
padding: 0;
}
</style>
import axios from 'axios';
import qs from 'qs';
axios.defaults.timeout = 10000;
let base = "http://192.168.1.164:8282/gic/";
const timeout = 10000;
let token = ''//sessionStorage.getItem('user');
/*
*
* 统一 get 请求方法
* @url: 请求的 url
* @params: 请求带的参数
* @header: 带 token
*
*/
export const getRequest = (url, params) => {
return axios({
method: 'get',
url: `${base}${url}`,
data: {},
params: params,
headers: {'content-type': 'application/x-www-form-urlencoded'},// "token": token
});
}
import vueOfficeHeader from './vue-office-header.vue' // 导入组件
const vueOffice = {
install(Vue, options) {
Vue.component(vueOfficeHeader.name, vueOfficeHeader) // vueGicHeader.name 组件的name属性
// 类似通过 this.$xxx 方式调用插件的 其实只是挂载到原型上而已
// Vue.prototype.$xxx // 最终可以在任何地方通过 this.$xxx 调用
// 虽然没有明确规定用$开头 但是大家都默认遵守这个规定
}
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(vueOffice);
}
export default vueOffice
// export {
// vueOfficeHeader
// }
<template>
<div class="navheader">
<!-- logo -->
<div class="navheader-logo fl" :class="{moveleft: isCollapse ,moveright: !isCollapse}">好办管理平台</div>
<div class="navheader-item fl">
<a class="itemlink" @click="handleCollapse">
<i class="iconfont" :class="{'icon-shouqi': isCollapse,'icon-zhankai': !isCollapse}"></i>
</a>
<!-- <a :class="['itemlink', 'bottom','menu-all',summaryName=='/index'? 'current-module':'']" :href="origin+'/report/#/memberSummary'">首页</a>
<div :class="['itemlink-gic', 'bottom', pathName=='gic-web'? 'current-module':'']">GIC商户后台</div> -->
<!-- menu -->
<template v-for="menuitem in menuHead">
<a :class="['itemlink', 'bottom','menu-mall',pathName==menuitem.menuUrl? 'current-module':'']" :href="'#'+menuitem.menuUrl" :target="menuitem.target == 1?'_blank':''">{{menuitem.menuName}}</a>
</template>
<!-- 最右侧用户信息 -->
<div class="navuserinfo fr">
<el-button @click="toGicLogin">GIC管理平台</el-button>
<el-button type="text" @click="toLoginOut">退出</el-button>
</div>
</div>
</div>
</template>
<script>
// import { getRequest } from './api';
import qs from 'qs';
export default {
name: 'vue-office-header',
props: ['menuRouter','collapseFlag','projectName'],
data () {
return {
repProjectName: 'gic-web', // 项目名
// 当前路由
pathName: '',
isCollapse: false,// 是否收起左侧
// 菜单数据
menuHead: [
{
menuCode: null,
menuName: "首页",
menuUrl: "/index",
parentCode: null,
project: "office"
},
{
menuCode: null,
menuName: "通讯录",
menuUrl: "/administrativeFrame",
parentCode: null,
project: "office"
},
{
menuCode: null,
menuName: "企业应用",
menuUrl: "/enterpriseApp",
parentCode: null,
project: "office"
},
{
menuCode: null,
menuName: "审核中心",
menuUrl: "/unreview",
parentCode: null,
project: "office"
},
{
menuCode: null,
menuName: "我的企业",
menuUrl: "/unreview",
parentCode: null,
project: "office"
},
{
menuCode: null,
menuName: "设置",
menuUrl: "/companyAddress",
parentCode: null,
project: "office"
},
],
// 获取 location origin
baseUrl: '',
routePathName: '', // 当前路由值
}
},
beforeMount() {
var that = this
var host = window.location.origin;
console.log("当前host:",host)
if (host.indexOf('localhost') != '-1') {
that.baseUrl = 'http://gicdev.demogic.com';
}else {
that.baseUrl = host
}
},
methods: {
// 处理折叠
handleCollapse() {
var that = this;
that.isCollapse = (that.isCollapse==true? false: true);
that.$emit('collapseTag', that.isCollapse)
},
// 跳转 gic 管理后台
toGicLogin() {
window.location.href = window.location.origin + '/gic-web/#/';
},
//退出登录
toLoginOut() {
var that = this;
// var para = {
// requestProject: that.repProjectName
// }
that.$confirm('确认退出吗?', '提示', {
type: 'warning'
}).then(() => {
that.axios.post(that.baseUrl+'/api-auth/do-logout',{})
.then((res) => {
// console.log(res,res.data,res.data.errorCode)
var resData = res.data
if (resData.errorCode == 0) {
that.$message({
message: '退出成功',
type: 'success'
});
// 跳转登录页
window.location.href = window.location.origin + '/gic-web/#/';
return;
}
that.$message.error({
duration: 1000,
message: resData.message
})
})
.catch(function (error) {
console.log(error);
that.$message.error({
duration: 1000,
message: error.message
})
});
}).catch(() => {
console.log(error);
that.$message.error({
duration: 1000,
message: error.message
})
});
},
// 触发父组件路由
toRouter(path,name,code) {
var that = this;
var obj ={
path: '/'+ path,
name: name
}
that.$emit('toRouterView', obj)
},
// 获取菜单
getHeaderMenu() {
var that = this
var para = {
project: that.repProjectName,
requestProject: that.repProjectName
}
that.axios.post(that.baseUrl + '/api-auth/login-clerk-menu',qs.stringify(para))
.then((res) => {
// console.log(res,res.data,res.data.errorCode)
var resData = res.data
if (resData.errorCode == 0) {
that.menuHeadRouter = resData.result;
console.log(that.menuHeadRouter)
// that.setNewData(resData.result)
// 获取左侧菜单
that.getLeftMenu()
return;
}
that.$message.error({
duration: 1000,
message: resData.message
})
})
.catch(function (error) {
console.log(error);
// that.toLogin()
that.$message.error({
duration: 1000,
message: error.message
})
});
},
},
watch: {
$route: {
handler: function(val, oldVal){
console.log("获取当前路由:",val);
var that = this
},
// 深度观察监听
deep: true
},
collapseFlag: function(newData,oldData){
var that = this;
that.isCollapse = newData
},
projectName: function(newData,oldData){
var that = this;
that.repProjectName = newData || 'gic-web';
},
},
/* 接收数据 */
mounted(){
console.log("传递的参数对象:",this.collapseFlag)
var that = this;
that.pathName = that.$route.path
//获取项目名 pathname (路由的hash)
that.routePathName = window.location.hash.split('/')[1];
if (that.routePathName.indexOf('?')!= -1) {
that.routePathName = that.routePathName.split('?')[0]
}
if (that.routePathName.indexOf('/')!= -1) {
that.routePathName = that.routePathName.split('/')[0]
}
console.log("routePathname:",that.routePathName)
// 项目名
that.repProjectName = that.projectName || 'gic-web';
that.isCollapse = that.collapseFlag
// 获取菜单
that.getHeaderMenu();
},
}
</script>
<style lang="less" scoped>
@base-color: #353944;
@hover-color: #3c92eb;
@hoverbg-color: #20242d;
@main-color: #1890ff;
@navbgcolor: #04143a;
@sidebgcolor: #020b21;
@userinfobgcolor: #ecf5ff;
@contentbgcolor: #f5f7fa;
@bordercolor: #dcdfe6;
@customnavcolor: #04143a;
@btnbgcolor: #f5f7fa;
@iconbgcolor: #e6e9f2;
@elmenuisactive: #1890ff;
.flex1(@width,@height) {
flex: 0 0 @width;
width: @width;
height: @height;
}
.navheader /deep/ {
position: fixed;
display: flex;
top: 0;
left: 0;
width: 100%;
/*min-width: 1400px;*/
height: 64px;
line-height: 64px;
font-size: 14px;
background-color: #fff;
padding: 0;
z-index: 99;
color: #fff;
.fl {
float: left;
}
.fr {
float: right;
}
&-logo {
flex: 0 0 200px;
width: 200px;
height: 64px;
float: left;
padding-left: 28px;
font-size: 20px;
color: #1F2F3D;
text-align: center;
background: url("./logo.png") no-repeat 20px center;
}
&-pic {
vertical-align: middle;
}
&-item {
flex: 1;
box-shadow: 5px -1px 10px #ddd;
}
.itemlink {
float: left;
padding: 0 20px;
display: inline-block;
height: 62px;
cursor: pointer;
color: #606266;
&:hover {
color: @main-color;
}
}
.bottom:hover {
border-bottom: 2px solid @main-color;
}
/* 选中 */
.current-module.bottom {
color: @main-color;
border-bottom: 2px solid @main-color;
font-weight: 500;
}
/* logo */
.moveleft {
margin-left: -136px;
transition: all .3s ease;
background-position: 151px 10px;
color: transparent;
}
.moveright {
margin-left: 0px;
transition: all .2s ease;
}
}
li {
list-style: none;
}
/*用户信息*/
.navuserinfo {
/*width: 140px;*/
/*font-size: 0;*/
text-align: center;
.el-button--text {
padding-right: 24px;
font-size: 14px;
color: #606266;
margin-left: 30px;
}
}
/* 当浏览器的可视区域小于1280px */
@media screen and ( max-width: 1280px ) {
.navheader {
min-width: 1280px
}
}
@media screen and (min-width: 1280px) and ( max-width: 1366px ) {
.navheader {
min-width: 1280px
}
}
@media screen and (min-width: 1366px) and ( max-width: 1440px ) {
.navheader {
min-width: 1366px
}
}
@media screen and (min-width: 1440px) and ( max-width: 1920px ) {
.navheader {
min-width: 1440px
}
}
</style>
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
var path = require('path')
var webpack = require('webpack')
module.exports = {
// entry: './src/main.js',
entry: './src/lib/index.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: './',
// filename: 'build.js',
filename: 'vue-office-header.js',
library: 'vue-office-header',
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
]
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
// options: {
// name: '[name].[ext]?[hash]'
// },
query : {
name : 'static/img/[name].[ext]?[hash]'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment