Commit fc304e56 by tangjiale

更新url配置,跳转配置

parent 083f2195
<template>
<a :href="finalUrl" :target="target" :rel="rel">
<slot></slot>
</a>
</template>
<script type="text/babel">
import { $link } from '../plugins/routerLinks'
export default {
name: 'RLink',
components: {},
props: {
rel: String,
// 传入的页面标识
tag: {
type: String,
default: function () {
return ''
}
},
// 跳转页面的方式
target: {
type: String,
default: function () {
return '' //_blank _parent _self _top
}
},
// 外链地址
link: {
type: String,
default: function () {
return ''
}
},
// 跳转参数拼接
params: {
type: Object,
default: function () {
return {}
}
},
query:{
type: Object,
default: function () {
return {}
}
}
},
data () {
return {
urls: ''
}
},
computed: {
finalUrl () {
if (!this.link) {//非外链
if (this.tag) {
return $link.getUrl(this.tag, this.params,this.query)
} else {
return 'javascript:void(0)'
}
} else { //跳转到别的域名
return this.link
}
}
}
}
</script>
export default (context) => {
// 处理asyncData返回的数据,添加公共数据
context.returnData = function (data) {
if (process.server) {
let canonicalUrl = `https://www.cnhnb.com${context.req.originalUrl}`;
return Object.assign({
canonicalUrl
}, data);
}
};
}
\ No newline at end of file
...@@ -13,7 +13,7 @@ const envMap = { ...@@ -13,7 +13,7 @@ const envMap = {
const ENV_SCRIPT = { const ENV_SCRIPT = {
'dev': [ 'dev': [
// {src: '//files.cnhnb.com/eyejs/app.v1.0.0.js'}, // {src: '//files.cnhnb.com/eyejs/app.v1.0returnData.0.js'},
// {src: '//files.cnhnb.com/eyejs/m-sso-test.v1.0.2.js'}, // {src: '//files.cnhnb.com/eyejs/m-sso-test.v1.0.2.js'},
// {src: '//files.cnhnb.com/eyejs/peach.v1.1.0.js'} // {src: '//files.cnhnb.com/eyejs/peach.v1.1.0.js'}
], ],
...@@ -49,14 +49,18 @@ module.exports = { ...@@ -49,14 +49,18 @@ module.exports = {
router: { router: {
base: '', base: '',
// middleware: [ '' ], middleware: [ 'returnData' ],
extendRoutes (routes) { extendRoutes (routes) {
return [ return [
...routes, ...routes,
{ {
path: '/test1', path: '/tired/:id(\\d+)/',
component: '~/ssr/tired/_id.js'
},
{
path: '/',
component: '~/ssr/test.js' component: '~/ssr/test.js'
} },
]; ];
} }
}, },
...@@ -71,7 +75,7 @@ module.exports = { ...@@ -71,7 +75,7 @@ module.exports = {
], ],
head: { head: {
title: '', title: pkg.name,
meta: [ meta: [
{charset: 'utf-8'}, {charset: 'utf-8'},
{ {
......
<template> <template>
<div> <div>
hello,{{ip}} hello,{{ip}}
<img src="../assets/images/img-default.jpg" style="width: 200px;">
<br/><br/> <br/><br/>
<div @click="loginUrl"> <div @click="loginUrl">
...@@ -16,19 +15,18 @@ ...@@ -16,19 +15,18 @@
const TOKEN_TIME = 60 * 60 * 1000 * 24 * 89; // 89天过期时间 const TOKEN_TIME = 60 * 60 * 1000 * 24 * 89; // 89天过期时间
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
const HN_USER_TICKET_KEY = 'hnUserTicket'; const HN_USER_TICKET_KEY = 'xbtyToken';
const HN_USER_ID_KEY = 'hnUserId';
export default { export default {
async asyncData (ctx) { async asyncData ({app,query,params,redirect,returnData}) {
// let result = await service(TestService);
console.log(ctx.app.$axiosApi) console.log('参数是什么',params)
// let ip = '' console.log(app.$axiosApi)
let ip = await ctx.app.$axiosApi('/sport/new/screen/getMidUrl',{regionCode:430103000000},{})
let ip = await 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('mangapi/sport/new/screen/getMidUrl',{regionCode:430103000000})
// const ip = await $axios.$get('http://test.xiaobentiyu.cn/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) console.log('服务端渲染接口sport/new/screen/getMidUrl:',ip)
return { ip } return { ip }
}, },
data () { data () {
...@@ -48,7 +46,6 @@ ...@@ -48,7 +46,6 @@
let domain = this.$config.env === 'dev' ? 'localhost:3001' : '.cnhnb.com'; 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_TICKET_KEY, 'ticketticket', {expires: exp, path: '/', domain});
Cookies.set(HN_USER_ID_KEY, '569321', {expires: exp, path: '/', domain});
} }
} }
}; };
......
...@@ -10,6 +10,12 @@ import Vue from 'vue'; ...@@ -10,6 +10,12 @@ import Vue from 'vue';
let config = require(`@/config/${process.env.ENV_CONFIG||'pro'}.config.json`); let config = require(`@/config/${process.env.ENV_CONFIG||'pro'}.config.json`);
Vue.prototype.$config = config Vue.prototype.$config = config
import RouterLink from './routerLinks'
import Link from '../components/Link'
Vue.component(Link.name, Link)
Vue.use(RouterLink)
// Vue.prototype.$showConfirm = msg => Vue.prototype.$confirm(msg || '是否确定删除对应的记录?', '提示', {type: 'warning'}); // Vue.prototype.$showConfirm = msg => Vue.prototype.$confirm(msg || '是否确定删除对应的记录?', '提示', {type: 'warning'});
// Vue.prototype.$notifySuccess = msg => Vue.prototype.$notify.success({ // Vue.prototype.$notifySuccess = msg => Vue.prototype.$notify.success({
......
const PAGE_MAP = {
'index': '/', // 首页
'yxProduct': process.env.ENV_CONFIG === 'pro' ?
'https://yxmall.cnhnb.com/goods/${id}/' : 'https://yxmall.cnhnkj.cn/goods/${id}/', // 优选商品主页
'purchaseSearch': '/purchase/${pinyin}-0-${areaId}-${breedId}-${specId}-${pageNum}/',// 采购大厅(类目地区品种规格)
'dxCourseDetail':'https://daxue.cnhnb.com/w/info-${id}.html', //成长中心课程详情
'bigdata':'/bigdata/' //惠农大数据
}
let $link = {
go (tag, params, query) {
location.href = this.getUrl(tag, params, query)
},
/**
* 传入tag,返回url
*/
getUrl (tag, params, query) {
let url = PAGE_MAP[tag]
if (url && url.indexOf('$') !== -1) { // 需要替换参数
return this._concatParams(url, params, query)
}
return this._contactUrl(url, params)
},
_concatParams(url, obj, query) {
let i = url.substr(0, url.length - 1).lastIndexOf('/');
let paramExp = url.substring(i + 1, url.length - 1); // 截出url表达式里的参数部分,取最后两个/中间的内容
let params = paramExp.split('$');
params.forEach(v => {
let paramName = v.substring(v.indexOf('{') + 1, v.indexOf('}'));
if (obj && obj[paramName]) {
url = url.replace('${' + paramName + '}', obj[paramName]); // 如果传进来的参数名跟表达式的一样,把对应的值替换上
} else {
url = url.replace('${' + paramName + '}',
paramName === 'pageNum' ? 1 : 0); // 否则默认替换成0(如果是页码的话就是1)
}
});
return this._contactUrl(url, query);
},
/**
* 将URL和参数拼接起来
* @param url 传入的URL
* @param obj 传入的页面参数Object
*/
_contactUrl (url, obj = {}) {
if (!url || url.indexOf('?') !== -1) {
return url
}
let urlParms = []
let objKey = Object.keys(obj)
objKey.forEach(item => {
urlParms.push(item + '=' + obj[item])
})
let destUrl = url
if (urlParms.length) {
destUrl = destUrl + '?' + urlParms.join('&')
}
return destUrl
}
}
export {
$link
}
export default {
install (Vue) {
Vue.prototype.$link = $link
}
}
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