Commit 083f2195 by tangjiale

初始化框架

parents
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# Nuxt generate
dist
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless
# IDE
.idea
.DS_Store
package-lock.json
.ssr
<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
<head {{ HEAD_ATTRS }}>
{{ HEAD }}
<script type="text/javascript">
var _hmt = _hmt || [];
(function() {
var hm = document.createElement('script');
hm.src = 'https://hm.baidu.com/hm.js?e34899ebe785ba2d1ad7fa67c68b108b';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body {{ BODY_ATTRS }}>
{{ APP }}
</body>
</html>
\ No newline at end of file
* {
padding: 0;
margin: 0;
outline: none;
box-sizing: border-box;
border: none;
}
a {
text-decoration: none;
}
ul li {
list-style: none;
}
a:hover {
color: #45B035;
}
font {
font-family: PingFangSC-Regular;
letter-spacing: 0;
}
.g-content {
position: relative;
margin: 0 auto;
width: 1200px;
}
.clear-fix {
zoom: 1;
clear: both;
}
::-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: #ddd;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #ddd;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #ddd;
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #ddd;
}
.eye-pagination__editor.eye-input .eye-input__inner {
height: 37px !important;
border: none;
border-radius: 0;
}
.eye-pagination__editor {
line-height: 18px!important;
height: 38px;
text-align: center;
margin: 0 2px;
box-sizing: border-box;
}
{
"env":"dev",
"monk":"http://tiyuadmin.youchengzhang.cn",
"pigsy":"http://tiyuadmin.youchengzhang.cn"
}
{
"env": "pro",
"pigsy":"https://appapi.cnhnb.com"
}
//
// import {Context,Service} from '../plugins/framework/index'
//
// import Bean from '../plugins/framework'
//
// export default (context) => {
// context.service = function(service) {
//
// let env = Context.$config.env;
// let config = require(`../config/${env}.config.json`);
//
//
//
//
// console.log('---------service--------',JSON.stringify(service))
//
// console.log('---------Context--------',Context)
//
// // let base = Context.$config[ o.domainKey || 'monk' ]; // 获取host
//
// console.log('---------context--------',context)
// };
// }
const pkg = require('./package');
const envMap = {
'dev': {
NODE_ENV: 'development',
ENV_CONFIG: 'dev'
},
'pro': {
NODE_ENV: 'production',
ENV_CONFIG: 'pro'
}
};
const ENV_SCRIPT = {
'dev': [
// {src: '//files.cnhnb.com/eyejs/app.v1.0.0.js'},
// {src: '//files.cnhnb.com/eyejs/m-sso-test.v1.0.2.js'},
// {src: '//files.cnhnb.com/eyejs/peach.v1.1.0.js'}
],
'pro': [
// {src: '//files.cnhnb.com/eyejs/app.v1.0.0.js'},
// {src: '//files.cnhnb.com/eyejs/m-sso.v1.0.3.js'},
// {src: '//files.cnhnb.com/eyejs/peach.v1.1.0.js'}
]
};
const envValue = process.env.ENV_CONFIG;
const env = envMap[ envValue ];
const getPkgVersion = v => {
return {
test: new RegExp(v),
enforce: true,
name: v + '-' + (pkg.dependencies[ v ] ? pkg.dependencies[ v ].replace(
/[^0-9 | \.]/ig, '') : ''),
chunks: 'all'
};
};
module.exports = {
mode: 'universal',
dir: {
pages: 'ssr'
},
buildDir: '.ssr',
router: {
base: '',
// middleware: [ '' ],
extendRoutes (routes) {
return [
...routes,
{
path: '/test1',
component: '~/ssr/test.js'
}
];
}
},
server: {
host: '0.0.0.0'
},
modules: [
'@nuxtjs/axios',
'cookie-universal-nuxt'
],
head: {
title: '',
meta: [
{charset: 'utf-8'},
{
name: 'viewport',
content: 'width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'
},
{hid: 'description', name: 'description', content: pkg.description},
{
name: 'robots',
content: 'index,follow'
},
{
name: 'baidu-site-verification',
content: '84FlZTfdd0'
}
],
// link: [ {
// rel: 'icon',
// type: 'image/x-icon',
// href: '//files.cnhnb.com/h5/assets/favicon.ico'
// } ],
script: ENV_SCRIPT[ envValue ]
},
css: [
// '@/assets/css/icon-font.css'
],
plugins: [
'@/plugins/axios.js',
'~/plugins/index',
],
build: {
babel: {
presets: [ '@babel/preset-env' ],
plugins: [
'@babel/plugin-proposal-class-properties',
[
'@babel/plugin-transform-runtime',
{
'helpers': false,
'regenerator': true
}
],
[ '@babel/syntax-dynamic-import' ]
]
},
postcss: [
// require('postcss-px2rem')({
// remUnit: 37.5
// }),
require('autoprefixer')
],
// transpile: [ /^vant/, /eye-/ ],
//
// filenames: {
// chunk: ({isDev}) => isDev ? '[name].js' : '[name].[contenthash].js',
// app: ({isDev}) => isDev ? '[name].js' : '[name].[chunkhash].js'
// },
// optimization: {
// runtimeChunk: 'multiple',
// splitChunks: {
// name: true,
// cacheGroups: {
// 'nuxt': getPkgVersion('nuxt'),
// 'eye-com': getPkgVersion('eye-com'),
// 'eye-core': getPkgVersion('eye-core'),
// 'eye-ui': getPkgVersion('eye-ui'),
// 'eye-wap': getPkgVersion('eye-wap'),
// 'vant': getPkgVersion('vant')
// }
// }
// },
extend (config, ctx) {
}
},
env: {
...env
}
};
{
"name": "test",
"version": "1.0.0",
"description": "A Eye7 Web Project",
"private": true,
"scripts": {
"dev-ssr": "cross-env ENV_CONFIG=dev ssr=true nuxt -o --port=3001",
"dev-ssr-prod": "cross-env IS_LOCAL=1 ENV_CONFIG=pro ssr=true nuxt -o --port=3001",
"generate": "cross-env ENV_CONFIG=dev nuxt generate",
"generate-prod": "cross-env ENV_CONFIG=pro nuxt generate"
},
"dependencies": {
"@nuxtjs/axios": "^5.8.0",
"autoprefixer": "^9.7.2",
"babel-polyfill": "6.26.0",
"js-cookie": "2.2.1",
"cookie-universal-nuxt": "2.0.19",
"cross-env": "5.2.0",
"less": "3.10.3",
"less-loader": "5.0.0",
"lib-flexible": "0.3.2",
"nuxt": "2.9.2",
"postcss-loader": "3.0.0",
"postcss-px2rem": "0.3.0",
"vant": "2.12.6",
"vue-loader": "15.7.1"
}
}
<template>
<div>
hello,{{ip}}
<img src="../assets/images/img-default.jpg" style="width: 200px;">
<br/><br/>
<div @click="loginUrl">
cookie登录
</div>
</div>
</template>
<script>
// import { Page } from 'eye-core';
// import TestService from '../services/TestService';
const TOKEN_TIME = 60 * 60 * 1000 * 24 * 89; // 89天过期时间
import Cookies from 'js-cookie';
const HN_USER_TICKET_KEY = 'hnUserTicket';
const HN_USER_ID_KEY = 'hnUserId';
export default {
async asyncData (ctx) {
// let result = await service(TestService);
console.log(ctx.app.$axiosApi)
// let ip = ''
let ip = await ctx.app.$axiosApi('/sport/new/screen/getMidUrl',{regionCode:430103000000},{})
// const ip = await $axios.$get('mangapi/sport/new/screen/getMidUrl',{regionCode:430103000000})
// const ip = await $axios.$get('http://test.xiaobentiyu.cn/mangapi/sport/new/screen/getMidUrl?regionCode=430103000000')
console.log('前端返回结果',ip)
return { ip }
},
data () {
return {
ip: ''
};
},
mounted(){
// this.$axiosApi('/sport/new/screen/getMidUrl',{regionCode:430103000000},{
//
// })
},
methods:{
loginUrl(){
let exp = new Date();
exp.setTime(exp.getTime() + TOKEN_TIME);
let domain = this.$config.env === 'dev' ? 'localhost:3001' : '.cnhnb.com';
Cookies.set(HN_USER_TICKET_KEY, 'ticketticket', {expires: exp, path: '/', domain});
Cookies.set(HN_USER_ID_KEY, '569321', {expires: exp, path: '/', domain});
}
}
};
</script>
<style scoped lang='less'>
</style>
import Vue from 'vue'
import qs from 'qs';
let config = require(`@/config/${process.env.ENV_CONFIG||'pro'}.config.json`);
export default ({app:{ $axios, redirect, router, store}},inject) => {
//配置域名
$axios.defaults.baseURL = config.pigsy
//设置请求头功能属性
$axios.setHeader('Content-Type', 'application/json') //请求类型 默认json
//默认超时时间
$axios.defaults.timeout = 10000
// 请求拦截
$axios.onRequest(config => {
// if (store.getters && store.getters.token) {
// config.headers.authorization = 'Bearer ' + store.getters.token
// }
return config
})
// 响应拦截
$axios.onResponse(response => {
// 做些业务需要的处理
const resp = response.data
return resp
})
//错误拦截
$axios.onError(error => {
return Promise.reject(error)
})
// 向nuxt注入一个内置的方法
inject('axiosApi', (url, params, option) => {
/**
* 获取动态配置域名 base
*/
let base = config[ option.domainKey || 'monk' ]
/**
* 自定义配置请求头 option
*/
let headers = {
'tangjiale':'asdasdasdadasdasdada'
}
//请求类型,默认get
let method = option.method || 'get'
//自定义转换类型,默认json
if (option.contentType && option.contentType === 'form') {
Object.assign(headers, {
'Content-Type': 'application/x-www-form-urlencoded'
});
params = qs.stringify(params);
} else {
Object.assign(headers, {
'Content-Type': 'application/json'
});
}
let finalHeaders = Object.assign(headers, headers);
return new Promise((resolve, reject) => {
//TODO $get只返回data get会返回包含code和data的数据对象
$axios[ method == 'get' ? 'get' : ('$' + method) ](
url, method === 'get' ? {params: params} : params, {headers: finalHeaders}).then(res => {
if (res.code && res.code == 200) {
resolve(res.data)
} else {
return Promise.reject(res);
}
}).catch(err => {
console.error(JSON.stringify({
host: base,
url: url,
data: params,
headers: finalHeaders,
reqError: JSON.stringify(err)
}));
throw new Error(JSON.stringify(err));
});
})
})
}
/*
* @Author: tangjiale
* @eMail: 932055106@qq.com
* @Date: 2022-02-10 15:24:49
* @LastEditors: tangjiale
* @LastEditTime: 2022-02-18 09:32:53
*/
import Vue from 'vue';
let config = require(`@/config/${process.env.ENV_CONFIG||'pro'}.config.json`);
Vue.prototype.$config = config
// Vue.prototype.$showConfirm = msg => Vue.prototype.$confirm(msg || '是否确定删除对应的记录?', '提示', {type: 'warning'});
// Vue.prototype.$notifySuccess = msg => Vue.prototype.$notify.success({
// title: '提示',
// message: msg || '操作成功',
// position: 'bottom-right'
// });
// Vue.prototype.$px2rem = Number(document.documentElement.style.fontSize.replace('px', '')) / 75 * (window.dpr || 1);
export default ({store}) => {
// Vue.directive('auth', {
// bind: function(el, binding) {
// let authCode = binding.value;
// if (!authCode) return;
// if (store.state.buttonAuthList.indexOf(authCode) === -1) { // 没有那个权限则隐藏按钮
// el.style.display = 'none';
// }
// }
// });
}
<style>
@keyframes opacity {
0% {
opacity: 1
}
50% {
opacity: .5
}
100% {
opacity: 1
}
}
</style>
<style>._ {
position: fixed;
z-index: 999;
background: #ecf0f2;
}
.__ {
top: 0%;
left: 0%;
width: 100%;
}</style>
<div class="_ __" style="height:100%;z-index:990;background:#fff"></div>
<div class="_" style="height:4.498%;top:1.047%;left:4.000%;width:92.000%"></div>
<div class="_" style="height:2.249%;top:8.918%;left:9.867%;width:22.400%"></div>
<div class="_" style="height:6.297%;top:13.491%;left:17.404%;width:14.925%"></div>
<div class="_" style="height:6.297%;top:13.491%;left:71.133%;width:7.462%"></div>
<div class="_" style="height:2.399%;top:23.686%;left:4.000%;width:92.000%"></div>
<div class="_" style="height:1.949%;top:27.734%;left:5.600%;width:11.200%;border-radius:15px"></div>
<div class="_" style="height:1.949%;top:27.734%;left:20.929%;width:13.867%;border-radius:15px"></div>
<div class="_" style="height:1.949%;top:27.734%;left:38.925%;width:5.867%;border-radius:15px"></div>
<div class="_" style="height:1.949%;top:31.182%;left:4.000%;width:92.000%"></div>
<div class="_" style="height:2.849%;top:35.378%;left:4.000%;width:6.796%"></div>
<div class="_" style="height:2.099%;top:36.277%;left:81.867%;width:10.133%;border-radius:27px"></div>
<div class="_" style="height:2.399%;top:43.324%;left:4.000%;width:92.000%"></div>
<div class="_" style="height:1.949%;top:47.372%;left:5.600%;width:11.200%;border-radius:15px"></div>
<div class="_" style="height:1.949%;top:47.372%;left:20.929%;width:14.604%;border-radius:15px"></div>
<div class="_" style="height:1.949%;top:47.372%;left:39.663%;width:5.867%;border-radius:15px"></div>
<div class="_" style="height:1.949%;top:50.820%;left:4.000%;width:92.000%"></div>
<div class="_" style="height:2.849%;top:55.015%;left:4.000%;width:15.854%"></div>
<div class="_" style="height:2.099%;top:55.915%;left:81.867%;width:10.133%;border-radius:27px"></div>
<div class="_" style="height:2.399%;top:62.961%;left:4.000%;width:92.000%"></div>
<div class="_" style="height:1.949%;top:67.009%;left:5.600%;width:11.200%;border-radius:15px"></div>
<div class="_" style="height:1.949%;top:67.009%;left:20.929%;width:14.604%;border-radius:15px"></div>
<div class="_" style="height:1.949%;top:67.009%;left:39.663%;width:5.867%;border-radius:15px"></div>
<div class="_" style="height:1.949%;top:70.458%;left:4.000%;width:92.000%"></div>
<div class="_" style="height:2.849%;top:74.653%;left:4.000%;width:15.854%"></div>
<div class="_" style="height:2.099%;top:75.553%;left:81.867%;width:10.133%;border-radius:27px"></div>
<div class="_" style="height:2.399%;top:82.599%;left:4.000%;width:92.000%"></div>
\ No newline at end of file
import container from '../pages/test';
container.head = function() {
return {
title: `${this.ip[0]} - 小本体育`,
meta: [
{
hid: 'description',
name: 'description',
content: '测试测试多url指向同一页面'
},
{
name: 'keywords',
content: '测试测试多url指向同一页面'
}
],
link: [],
};
};
export default container;
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