Commit c7b51f46 authored by 郭志伟's avatar 郭志伟

Merge branch 'feat/apollo' into 'master'

Feat/apollo

See merge request !18
parents a3a30c48 e5855e5e
......@@ -17,6 +17,8 @@ app/**/*.js
config/plugin.local.js
config/plugin.js
config/config.*.js
config/apollo.json
config/apollo.ssr.json
index.js
config/manifest.json
app/view/*
......
import { Controller, Context } from 'egg';
import * as path from 'path';
export default class ActivityController extends Controller {
public async home(ctx: Context) {
......@@ -9,7 +9,11 @@ export default class ActivityController extends Controller {
ctx.logger.info('请求redis成功 key: %j', redisKey);
}
if (!body) {
body = await ctx.renderView('activity.js', { url: ctx.url });
let apollo = {};
if (process.env.NODE_ENV === 'production' && process.env.EGG_SERVER_ENV === 'sit') {
apollo = ctx.app.config.apollo || {};
}
body = await ctx.renderView('activity.js', { url: ctx.url, apollo });
await ctx.service.redis.set(redisKey, body);
}
ctx.body = body;
......
module.exports = {
// Sentry options are required
organization: 'sentry',
project: 'quantum-blocks',
project: 'quantum-blocks-h5',
apiKey: '2e7e0678d81d4542b09cdbc35812f1cbb07a4993cd13435ba49d9511be11ec95',
// Release version name/hash is required
release: 'quantum-blocks@0.0.1',
baseSentryURL: 'http://sentry.quantgroups.com/api/0',
release: 'quantum-blocks-h5@0.0.1',
baseSentryURL: 'https://sentry.quantgroups.com/api/0',
deleteAfterCompile: true,
include: /js\//, // 只上传js和map文件
ignore: ['node_modules'],
......
......@@ -3,6 +3,6 @@ import config from '../config';
export default {
getPageById(params) {
return http.get(`${config.apiHost}editor/get/${params.pageId}`);
return http.get(`${config.apiHost}/editor/get/${params.pageId}`);
}
};
\ No newline at end of file
......@@ -11,7 +11,7 @@ import lazyload from '@qg/cherry-ui/src/lazyload/index';
// 初始化sentry
if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production') {
Raven.config('https://0785298052fd46128e201f30ca649102@sentry.q-gp.com/64', {
Raven.config('https://00ea2b4a57c94071a8d56f4548a42de2@sentry.quantgroups.com/66', {
release,
environment: 'production'
})
......
......@@ -3,7 +3,7 @@ const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'http';
export default {
// apiHost: `http://localhost:7001/`,
// apiHost: `http://192.168.28.199:7001/`,
apiHost: 'https://quantum-blocks-vcc2.liangkebang.net/',
apiHost: 'https://quantum-blocks-vcc2.liangkebang.net',
shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`,
// opapiHost: `https://opapi-vcc2.liangkebang.net`,
kdspHost: 'https://kdsp-api-vcc2.liangkebang.net',
......
const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https';
export default {
apiHost: `https://quantum-blocks.q-gp.com/`,
const hostMap = {
apiHost: `${protocol}//quantum-blocks.q-gp.com`,
shenceUrl: `${protocol}//bn.xyqb.com/sa?project=production`,
// opapiHost: `${protocol}//opapi.q-gp.com`,
test: false
};
export default hostMap;
import apolloSsr from '../../../config/apollo.ssr.json';
const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https';
export default {
apiHost: `https://quantum-blocks-test1.liangkebang.net/`,
// opApiHost: 'https://opapi-test1.liangkebang.net',
const hostMap = {
apiHost: `${protocol}//quantum-blocks-test1.liangkebang.net`,
shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`,
test: true
};
if (EASY_ENV_IS_BROWSER) {
const apolloWin = window.apollo || window.__INITIAL_STATE__.apollo;
if (apolloWin) {
for (const key in apolloWin) {
if (apolloWin[key]) {
hostMap[key] = apolloWin[key];
}
}
}
}
if (EASY_ENV_IS_NODE) {
if (apolloSsr) {
for (const key in apolloSsr) {
if (apolloSsr[key]) {
hostMap[key] = apolloSsr[key];
}
}
}
}
export default hostMap;
declare module "*.json" {
const value: any;
export default value;
}
\ No newline at end of file
import Vue from 'vue';
import { sync } from 'vuex-router-sync';
import initService from '@/service/init.service';
export default class App {
config: any;
constructor(config) {
......@@ -70,14 +69,13 @@ export default class App {
server() {
return context => {
// console.log('server', context.state);
const vm = this.create(context.state);
const { store, router } = vm;
router.push(context.state.url);
return new Promise((resolve, reject) => {
router.onReady(() => {
this.fetch(vm).then(() => {
context.state = store.state;
context.state = {...store.state, apollo: context.state.apollo};
return resolve(new Vue(vm));
});
});
......
declare var EASY_ENV_IS_NODE: boolean;
declare var EASY_ENV_IS_BROWSER: boolean;
type PlainObject<T = any> = { [key: string]: T };
interface Window {
__INITIAL_STATE__: string | any;
}
declare var apollo: any;
......@@ -103,6 +103,11 @@ export default class Activity extends Mixins(TransformStyleMixin, SaMixin) {
const transformY = transform.split('(')[1].split(')')[0].split(',')[5];
gridItemEle.style.top = `${transformY}px`;
gridItemEle.className += ' del_transform';
if (transform && transform.length) {
const transformY = transform.split('(')[1].split(')')[0].split(',')[5];
gridItemEle.style.top = `${transformY}px`;
gridItemEle.className += ' del_transform';
}
// 处理backgroundColor
const activityEle = document.querySelector('.activity');
const activityBgColor = getStyle(activityEle, 'backgroundColor');
......
......@@ -21,7 +21,10 @@ export default class EditorModule implements Module<EditorState, RootState> {
actions: ActionTree<EditorState, RootState> = {
async getPageDate({ commit }, condition) {
const [res] = await api.getPageById(condition);
const { page, ...rest } = res as PageInfo;
let { page, ...rest } = res as PageInfo;
if (!page) {
page = '[]';
}
commit(SET_PAGE_INFO, { ...rest, page: JSON.parse(page as string) });
}
};
......@@ -31,8 +34,8 @@ export default class EditorModule implements Module<EditorState, RootState> {
state.pageInfo = data;
},
[UPDATE_PAGE_INFO](state, { containerIndex, childIndex, data }) {
const page = (state.pageInfo.page as Page).elements;
if (childIndex || childIndex === 0) {
const page = (state.pageInfo.page as Page).elements || [];
if ((childIndex || childIndex === 0) && page[containerIndex].child) {
page[containerIndex].child.splice(childIndex, 1, data);
} else {
page.splice(containerIndex, 1, data);
......
#!/usr/bin/env node
"use strict";
const path = require('path');
const fs = require('fs');
const apollo = require('@qg/apollo-nodejs');
const npm = require("npm");
npm.load(() => {
apollo.load({
appId: 'quantum-block-h5',
configPath: path.resolve(__dirname, '../config'),
}).then(() => {
const { api, qiniu } = require(path.resolve('./config/apollo.json'));
fs.writeFileSync(path.resolve('./config/apollo.ssr.json'), JSON.stringify({ ...api, ...qiniu }));
});
});
\ No newline at end of file
#!/usr/bin/env node
"use strict";
const path = require('path');
const fs = require('fs');
const apollo = require('@qg/apollo-nodejs');
const npm = require("npm");
npm.load(() => {
apollo.load({
appId: 'quantum-block-h5',
configPath: path.resolve(__dirname, '../config'),
}).then(() => {
const { api, qiniu } = require(path.resolve('./config/apollo.json'));
fs.writeFileSync(path.resolve('./config/apollo.ssr.json'), JSON.stringify({ ...api, ...qiniu }));
if (process.env.NODE_ENV === 'production') {
npm.run("start");
} else {
npm.run("test");
}
});
});
\ No newline at end of file
......@@ -13,25 +13,14 @@ export default (appInfo: EggAppConfig) => {
dir: '/home/quant_group/logs',
};
const prodRedisConfig = {
exports.redis = {
client: {
port: 6379, // Redis port
host: 'front-redis.quantgroups.com', // Redis host
password: 'ln4^ESq80j4nrTMZ',
db: 0
}
};
const localRedisConfig = {
client: {
port: 31565, // Redis port
host: '172.17.5.13', // Redis host
password: '',
db: 0
}
};
exports.redis = process.env.NAMESPACE ? localRedisConfig : prodRedisConfig;
};;
return exports;
};
import { Application, EggAppConfig } from 'egg';
const path = require('path');
const { redis, api, qiniu } = require(path.resolve(__dirname, './apollo.json'));
export default (appInfo: EggAppConfig) => {
const exports: any = {};
exports.logger = {
dir: '/home/quant_group/logs',
};
exports.redis = {
client: redis
};
return exports;
return {...exports, apollo: { ...api, ...qiniu }};
};
declare module "*.json" {
const value: any;
export default value;
}
\ No newline at end of file
......@@ -3,12 +3,13 @@
"version": "0.0.1",
"description": "低代码平台",
"scripts": {
"start": "egg-scripts start --port 9050",
"test": "egg-scripts start --port 80 --workers 1",
"start": "cross-env NODE_ENV=production APOLLO_CLUSTER=3C egg-scripts start --port 9050",
"test": "cross-env NODE_ENV=production EGG_SERVER_ENV=sit DEBUG=apollo APOLLO_CLUSTER=k8s NAMESPACE=qa2 egg-scripts start --port 80 --workers 1",
"stop": "egg-scripts stop",
"backend": "nohup egg-scripts start --port 7001 --workers 4",
"dev": "egg-bin dev -r egg-ts-helper/register",
"debug": "egg-bin debug -r egg-ts-helper/register",
"apollo": "node bin/apollo.js",
"build": "cross-env COS_ENV=production easy build --devtool",
"build:test": "cross-env COS_ENV=test easy build --devtool",
"tsc": "ets && tsc -p tsconfig.json",
......@@ -62,7 +63,7 @@
"tslint-eslint-rules": "^5.4.0",
"tslint-loader": "^3.5.3",
"typescript": "^3.9.2",
"webpack-sentry-plugin": "^1.16.0"
"webpack-sentry-plugin": "^2.0.3"
},
"egg": {
"typescript": 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