Commit 14e1a5f4 by Lays-lzq

feat: csr改造

parent 4a5745d7
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
/* eslint-disable nuxt/no-cjs-in-config */
const path = require('path')
const WebpackAliOSSPlugin = require('@gdyfe/webpack-alioss-plugin')
const { getEnvConfig } = require('@gdyfe/config')
const { version, name } = require('./package.json')
const env = getEnvConfig({
server: process.env.mode,
ic: 'ZmUtZ5WNp%XBzDw='
})
const { X_CA_STAGE, RUN_SERVER, STATIC_SOURCE_DOMAIN, STATIC_OSS_ACCESS, OSS_DOMAIN } = env
const { SERVE_PORT, BASE_URL, PROJECT_NAME, SENTRY_DSN, GTAG_ID } = env.lottery
const IS_USE_OSS = process.env.NODE_ENV === 'production' && !!STATIC_OSS_ACCESS.accessKeyId
const plugins = IS_USE_OSS
? [
// 优化打包速度
new WebpackAliOSSPlugin({
accessKeyId: STATIC_OSS_ACCESS.accessKeyId,
accessKeySecret: STATIC_OSS_ACCESS.accessKeySecret,
region: STATIC_OSS_ACCESS.region,
bucket: STATIC_OSS_ACCESS.bucket,
prefix: PROJECT_NAME,
limit: 10, // 备份最近 10 个版本的 oss 文件
format: version,
exclude: [/.*\.html$/], // 或者 /.*\.html$/,排除.html文件的上传
deleteAll: false, // 优先匹配 format 配置项
output: path.resolve(__dirname, './nuxt-dist/dist/client'),
local: true // 上传打包输出目录里的文件
})
]
: []
const sentryConfig = IS_USE_OSS
? {
sentry: {
dsn: SENTRY_DSN,
config: {
name,
environment: RUN_SERVER,
release: version,
autoSessionTracking: false
},
lazy: true
}
}
: {}
const gtagConfig = IS_USE_OSS
? {
'google-gtag': {
id: GTAG_ID, // required
config: {
anonymize_ip: true,
send_page_view: false
}
}
}
: {}
export default {
buildDir: 'nuxt-dist',
env: {
...env,
UPLOADER_ACCESS: '',
STATIC_OSS_ACCESS: ''
},
router: {
base: BASE_URL,
middleware: ['device'],
extendRoutes(routes, resolve) {
routes.push({
path: '/',
redirect: '/list',
components: null
})
routes.push({
path: '/index/:id',
components: {
default: resolve(__dirname, 'pages/index') // or routes[index].component
}
})
}
},
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
title: '',
meta: [
{ charset: 'utf-8' },
{
name: 'viewport',
content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover'
},
{ hid: 'description', name: 'description', content: '' },
{ name: 'format-detection', content: 'telephone=no' },
{
hid: 'description',
name: 'description',
content: '问卷报表'
}
],
link: [
{
rel: 'stylesheet',
href: `//${OSS_DOMAIN}/common/icon/iconfont.css`,
ssr: false
},
{ rel: 'icon', href: `//${OSS_DOMAIN}/common/img/gdy_favicon.png` },
{ rel: 'stylesheet', href: `//${STATIC_SOURCE_DOMAIN}/web-component/complaintsDeal/complaintsDeal.min.css` },
{
href: '//apiliveroom.dev.guangdianyun.tv/v1',
rel: 'dns-prefetch'
},
{
href: '//activity.guangdianyun.tv',
rel: 'dns-prefetch'
},
{
href: '//static-pro.guangdianyun.tv',
rel: 'dns-prefetch'
},
{
href: '//res.wx.qq.com',
rel: 'dns-prefetch'
},
{
href: '//www.googletagmanager.com',
rel: 'dns-prefetch'
},
{
rel: 'stylesheet',
href: `//${STATIC_SOURCE_DOMAIN}/custom-plugins-library/login-center/style.css`,
},
],
script: [
{ src: `//${STATIC_SOURCE_DOMAIN}/web-component/complaintsDeal/complaintsDeal.min.js`, defer: true },
{
src: `//${STATIC_SOURCE_DOMAIN}/custom-plugins-library/login-center/login-center.min.js`
},
]
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: ['@/assets/styles/main.less'],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
{ src: '@/plugins/routeHooks' },
{ src: '@/plugins/vant' },
{ src: '@/filters' },
{ src: '@/plugins/vueClipboard' },
{ src: '@/plugins/dmsService', ssr: false },
{ src: '@/plugins/pvStatisticalService', ssr: false },
{ src: '@/plugins/deviceId', ssr: false }
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/eslint
'@nuxtjs/eslint-module',
'@nuxtjs/style-resources'
],
/* less全局变量 */
styleResources: {
less: './assets/styles/variable.less'
},
// Modules: https://go.nuxtjs.dev/config-modules
modules: ['@nuxtjs/axios', '@nuxtjs/sentry', '@nuxtjs/google-gtag'],
/*
** Axios module configuration
** See https://axios.nuxtjs.org/options
*/
...sentryConfig,
...gtagConfig,
axios: {},
server: {
https: !process.env.NODE_ENV === 'production',
port: SERVE_PORT, // default: 3000
host: '0.0.0.0' // default: localhost
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
publicPath: IS_USE_OSS
? `//${STATIC_SOURCE_DOMAIN}/${PROJECT_NAME}/${version}`
: `/${X_CA_STAGE.toLowerCase() || 'prod'}/`,
transpile: [/vant.*?less/],
babel: {
plugins: [
[
'import',
{
libraryName: 'vant',
style: name => {
return `${name}/style/less.js`
}
},
'vant'
]
]
},
postcss: {
plugins: {
'postcss-pxtorem': {
rootValue: 75,
selectorBlackList: [/^html$/, /^body$/, '.lottery-entry', 'tippy'], // 忽略转换正则匹配项
propList: ['*']
}
}
},
plugins
}
}
......@@ -7,9 +7,9 @@
"release": "standard-version",
"release:minor": "standard-version -r minor",
"release:patch": "standard-version -r patch",
"serve:dev": "cross-env mode=test nuxt",
"serve:pre": "cross-env mode=preview nuxt",
"serve:prod": "cross-env mode=production nuxt",
"serve:dev": "cross-env mode=test vue-cli-service serve",
"serve:pre": "cross-env mode=preview vue-cli-service serve",
"serve:prod": "cross-env mode=production vue-cli-service serve",
"serve:cm": "cross-env mode=cm nuxt",
"serve:vvku": "cross-env mode=vvku nuxt",
"serve:cbn": "cross-env mode=cbn nuxt",
......@@ -53,8 +53,9 @@
"lint": "yarn lint:js && yarn lint:style"
},
"dependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@easy-messenger/client-connection": "^1.0.3",
"@gdyfe/config": "^1.3.2",
"@gdyfe/config": "^2.0.1",
"@gdyfe/gdy-component-lib": "^0.4.1",
"@gdyfe/rop-client": "1.1.10",
"@nuxtjs/axios": "^5.13.6",
......@@ -73,7 +74,10 @@
"vconsole": "^3.9.1",
"vue-clipboard2": "^0.3.1",
"vue-cookie": "^1.1.4",
"vue-router": "^3.1.3",
"vuescroll": "^4.17.3",
"vuex": "^3.0.1",
"webpack": "^4.46.0",
"weixin-js-sdk": "^1.6.0"
},
"devDependencies": {
......@@ -83,6 +87,11 @@
"@nuxtjs/eslint-module": "^3.0.2",
"@nuxtjs/style-resources": "^1.2.0",
"@vant/touch-emulator": "^1.3.2",
"@vue/cli-plugin-babel": "^4.0.0",
"@vue/cli-plugin-eslint": "^4.0.0",
"@vue/cli-service": "^4.0.0",
"@vue/eslint-config-airbnb": "^4.0.0",
"@vue/eslint-config-prettier": "^6.0.0",
"babel-plugin-import": "^1.13.3",
"cross-env": "^7.0.3",
"eslint": "^7.29.0",
......
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<meta http-equiv="Cache-Control" content="no-store no-cache" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" /> -->
<link href="<%= BASE_URL %>config.js" rel="preload" as="script" />
<script src="<%= BASE_URL %>config.js"></script>
<title></title>
<script>
;(function() {
// Function to create and add a link element
function _addLink(href, rel) {
var linkTag = document.createElement('link')
linkTag.rel = rel
linkTag.href = href
document.head.appendChild(linkTag)
}
// Function to create and add a script element
function _addScript(src) {
var scriptTag = document.createElement('script')
scriptTag.src = src
document.head.appendChild(scriptTag)
}
// Add favicon and iconfont stylesheets
_addLink('//' + window.__GDY_ENV_CONFIG__.OSS_DOMAIN + '/common/img/gdy_favicon.png', 'icon')
_addLink('//' + window.__GDY_ENV_CONFIG__.OSS_DOMAIN + '/common/icon/iconfont.css', 'stylesheet')
_addLink('//' + window.__GDY_ENV_CONFIG__.OSS_DOMAIN + '/web-component/complaintsDeal/complaintsDeal.min.css', 'stylesheet')
_addLink('//apiliveroom.dev.guangdianyun.tv/v1', 'dns-prefetch')
_addLink('//activity.guangdianyun.tv', 'dns-prefetch')
_addLink('//static-pro.guangdianyun.tv', 'dns-prefetch')
_addLink('//res.wx.qq.com', 'dns-prefetch')
_addLink('//www.googletagmanager.com', 'dns-prefetch')
_addLink('//' + window.__GDY_ENV_CONFIG__.STATIC_SOURCE_DOMAIN + '/custom-plugins-library/login-center/style.css', 'stylesheet')
_addScript('//' + window.__GDY_ENV_CONFIG__.STATIC_SOURCE_DOMAIN + '/web-component/complaintsDeal/complaintsDeal.min.js')
_addScript('//' + window.__GDY_ENV_CONFIG__.STATIC_SOURCE_DOMAIN + '/custom-plugins-library/login-center/login-center.min.js')
})()
</script>
<style>
</style>
</head>
<body>
<noscript>
<strong
>We're sorry but web_lottery doesn't work properly without JavaScript enabled. Please enable it to
continue.</strong
>
</noscript>
<div id="app">
</div>
<!-- built files will be auto injected -->
</body>
</html>
<template>
<div id="app">
<router-view />
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
<style lang="less">
// html {
// // width: 100%;
// // height: 100%;
// // margin: 0;
// // padding: 0;
// // font-family: 'Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, 微软雅黑, Arial, sans-serif';
// body {
// width: 100%;
// height: 100%;
// margin: 0;
// padding: 0;
// #app {
// width: 100%;
// height: 100%;
// // background: #f7f7f7;
// }
// }
// }
</style>
/* eslint-disable no-confusing-arrow */
import { get, post } from '@/api/request'
import CONFIG from '@/config'
import CONFIG,{ ENV_CONFIG } from '@/config'
const { privateDomain } = CONFIG
const flag = process.env.X_CA_STAGE
const flag = ENV_CONFIG.X_CA_STAGE
// 获取地址列表
export const getAddressList = data =>
......
......@@ -7,9 +7,9 @@
4# 业务模块需要哪个接口则引入哪个
*/
import { get, post } from '@/api/request'
import CONFIG from '@/config'
import CONFIG, { ENV_CONFIG } from '@/config'
const { privateDomain, goDomain } = CONFIG
const flag = process.env.X_CA_STAGE
const flag = ENV_CONFIG.X_CA_STAGE
// 获取dms sub_key
export const getDmsInfo = data =>
......
/* eslint-disable no-confusing-arrow */
import { post, get } from '@/api/request'
import CONFIG from '@/config'
import CONFIG, { ENV_CONFIG } from '@/config'
const { activityDomain, privateDomain } = CONFIG
const flag = process.env.X_CA_STAGE
const flag = ENV_CONFIG.X_CA_STAGE
// 获取抽奖(场次)列表
export const getLotterySessionList = data =>
......
/* eslint-disable no-confusing-arrow */
import { post, get } from '@/api/request'
import CONFIG from '@/config'
import CONFIG, { ENV_CONFIG } from '@/config'
const { activityDomain } = CONFIG
const flag = process.env.X_CA_STAGE
const flag = ENV_CONFIG.X_CA_STAGE
// 获取个人抽奖记录
export const getRecordList = data =>
......
/* eslint-disable no-confusing-arrow */
import { get } from '@/api/request'
import CONFIG from '@/config'
import CONFIG, { ENV_CONFIG } from '@/config'
const { activityDomain } = CONFIG
const flag = process.env.X_CA_STAGE
const flag = ENV_CONFIG.X_CA_STAGE
// 获取留言抽奖中奖名单
export const getWinnersList = data =>
......
......@@ -4,6 +4,7 @@ import qs from "qs";
import VueCookie from "vue-cookie";
// message消息弹窗,可自行引入其他插件
import { Toast } from "vant";
import { ENV_CONFIG } from "@/config";
// 创建axios实例,不污染axios全局
const axiosService = axios.create();
......@@ -11,14 +12,14 @@ const axiosService = axios.create();
// 默认content-type
axiosService.defaults.headers["Content-Type"] = "application/x-www-form-urlencoded";
// 默认baseURL
axiosService.defaults.baseURL = `https://${process.env.CUSTOMER_API_DOMAIN}/v1`;
axiosService.defaults.baseURL = `https://${ENV_CONFIG.CUSTOMER_API_DOMAIN}/v1`;
// 默认请求超时时间
axiosService.defaults.timeout = 3 * 1000;
// 请求拦截器
axiosService.interceptors.request.use(
config => {
const token = VueCookie.get(process.env.CUSTOMER_TOKEN_KEY);
const token = VueCookie.get(ENV_CONFIG.CUSTOMER_TOKEN_KEY);
const { method, headers } = config;
const data = filterNull(config.data);
// 格式化序列,目前只对post进行处理,可新增其他请求逻辑
......@@ -34,11 +35,11 @@ axiosService.interceptors.request.use(
// config.data = { unused: 0 } // axios内部处理了get方法,使data无效
}
// 自定义header键:token
if (token && process.client) {
if (token) {
config.headers.token = token;
}
// 自定义header键:X-Ca-Stage(环境变量)
config.headers["X-Ca-Stage"] = process.env.X_CA_STAGE;
config.headers["X-Ca-Stage"] = ENV_CONFIG.X_CA_STAGE;
config.metadata = { startTime: new Date() };
return config;
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This source diff could not be displayed because it is too large. You can view the blob instead.
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 sign in to comment