Commit 7135df63 authored by rockyl's avatar rockyl

修复打包问题

parents efa3717a 0925bfb2
......@@ -4,11 +4,12 @@
* 项目相关api
*/
import {fetchApi} from "./common";
import { fetchApi } from "./common"
import { getCookie } from './utils'
export async function fetchAll(currentPage, pageSize, onlyMine) {
return await fetchApi('/api/project/query', {
params: {currentPage, pageSize, isAll: onlyMine ? 0 : 1},
params: { currentPage, pageSize, isAll: onlyMine ? 0 : 1 },
errMessage: 'Failed to fetch projects',
})
}
......@@ -31,7 +32,7 @@ export async function duplicateOne(project) {
export async function deleteOne(id) {
return await fetchApi('/api/project/delete', {
params: {id},
params: { id },
method: 'post',
errMessage: 'Failed to delete project',
})
......@@ -39,7 +40,7 @@ export async function deleteOne(id) {
export async function fetchOne(id) {
return await fetchApi('/api/project/query/data', {
params: {id},
params: { id },
method: 'get',
errMessage: 'Failed to fetch project',
})
......@@ -55,14 +56,14 @@ export async function fetchOneFromDataUrl(dataUrl) {
export async function fetchHistory(id, currentPage, pageSize) {
return await fetchApi('/api/project/history', {
params: {id, currentPage, pageSize},
params: { id, currentPage, pageSize },
method: 'get',
errMessage: 'Failed to history',
})
}
export async function saveOne(project, remark) {
project.remark = remark;
project.remark = remark
return await fetchApi('/api/project/update', {
params: project,
method: 'post',
......@@ -72,7 +73,7 @@ export async function saveOne(project, remark) {
export async function pack(id, debug, packedAssets) {
return await fetchApi('/api/project/pack', {
params: {id, debug, packedAssets},
params: { id, debug, packedAssets },
method: 'post',
errMessage: 'Failed to pack project',
})
......@@ -86,25 +87,57 @@ export async function importView(file) {
method: 'post',
contentType: 'form-data',
errMessage: 'Failed to import view',
});
response.__originFile = file;
return response;
})
response.__originFile = file
return response
}
export async function uploadFile(file, compress = false, uuid) {
let params = {file};
let params = { file }
if (compress) {
params.compress = true;
params.compress = true
}
if (uuid) {
params.uuid = uuid;
params.uuid = uuid
}
const response = await fetchApi('/api/uploadFile', {
params,
method: 'post',
contentType: 'form-data',
errMessage: 'Failed to upload file',
});
response.__originFile = file;
return response;
})
response.__originFile = file
return response
}
export async function saveSkins(params) {
return await fetchApi(`/polaris/autoSaveSkins`, {
params,
method: 'post'
})
}
export async function getProjectSkins(projectId, env) {
return await fetchApi(`/polaris/getProjectSkins?projectId=${projectId}&env=${env}`, {
method: 'post',
params: {
cookie: {
dev: getCookie('sso_ticket'),
test: localStorage.getItem('ticket'),
prod: localStorage.getItem('prod_ticket'),
}
}
})
}
export async function getTestEnvTicket() {
return await fetchApi(`/polaris/getTestEnvTicket`, { method: 'get' })
}
export async function getProdTicket() {
return await fetchApi(`/polaris/getProdTicket`, { method: 'get' })
}
export async function sendDingTalk() {
return await fetchApi(`/polaris/sendMessage`, { method: 'post' })
}
\ No newline at end of file
export function getCookie(name) {
var cookie = document.cookie,
pattern = /([^=]+)=([^;]+);?\s*/g,
result,
value = {}
while ((result = pattern.exec(cookie)) != null) {
value[result[1]] = result[2]
}
return value[name]
}
\ No newline at end of file
......@@ -114,6 +114,7 @@
"Builtin event should add directly": "内部事件请直接添加",
"Env constant": "自定义常量",
"Custom module": "自定义模块",
"Projectx config": "星速台配置",
"Custom module asset mapping": "自定义模块素材映射",
"Copy template to clipboard": "复制模板到粘贴板",
"Copied process to clipboard": "复制过程到粘贴板",
......
This diff is collapsed.
<template>
<div class="config">
<el-select
size="small"
v-model="currentEnv"
placeholder="请选择环境"
@change="changeCurrentEnv"
>
<el-option
v-for="item in env"
:key="item.value"
:label="item.name"
:value="item.value"
></el-option>
</el-select>
<el-select size="small" v-model="currentTypes" placeholder="是否新增">
<el-option
v-for="item in types"
:key="item.value"
:label="item.name"
:value="item.value"
></el-option>
</el-select>
<el-select
v-if="currentTypes !== '1'"
size="small"
v-model="skinId"
placeholder="选择skinID"
clearable
>
<el-option
v-for="item in skinList"
:key="item.id"
:label="`${item.type !== '1' ? item.name : '首页'}(${item.id})`"
:value="item.id"
></el-option>
</el-select>
<div v-if="currentTypes === '1'">
<el-select size="small" v-model="currentHtmlType" placeholder>
<el-option
v-for="item in htmlType"
:key="item.value"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
<el-input
v-model="name"
size="small"
class="name"
placeholder="请输入皮肤名称"
></el-input>
</div>
&nbsp;
<el-button type="primary" size="small" @click="saveSkins">保存</el-button>
<el-button v-if="skinId" type="primary" size="small" @click="getUrl"
>获取链接</el-button
>
</div>
</template>
<script>
import { mapState } from "vuex";
import copy from "copy-to-clipboard";
import {
getProjectSkins,
saveSkins,
getTestEnvTicket,
getProdTicket,
sendDingTalk
} from "../../../../src/api/project";
export default {
name: "ProjectxOptions",
props: {
tpl: String
},
data() {
return {
env: [
{ value: "dev", name: "开发环境" },
{ value: "test", name: "测试环境" },
{ value: "prod", name: "线上环境" }
],
currentEnv: "dev",
types: [
{ value: "1", name: "新增" },
{ value: "2", name: "修改" },
{ value: "3", name: "删除" }
],
currentTypes: "2",
skinId: "",
htmlType: [
{ value: "1", label: "首页" },
{ value: "2", label: "其他" }
],
currentHtmlType: "1",
skinList: [],
projectId: "",
name: ""
};
},
computed: {
...mapState(["project"])
},
methods: {
getProjectId(env) {
const { projectxConfig } = this.project.data.options;
this.projectId = projectxConfig[env];
return this.projectId;
},
changeCurrentEnv(e) {
if (e === "test") {
this.getTicket(getTestEnvTicket);
} else if (e === "prod") {
this.getTicket(getProdTicket, "prod_ticket");
}
const projectId = this.getProjectId(e);
this.skinId = "";
this.getSkinsList(projectId);
},
async getSkinsList(projectId) {
const { currentEnv } = this;
if (!projectId) {
this.$message({
message: `请先配置${currentEnv}环境下的projectId`,
type: "error"
});
return;
}
try {
const data = await getProjectSkins(projectId, currentEnv);
if (data.success !== false) {
this.skinList = data;
} else {
// 如果是测试环境,ticket过期,则重新获取ticket
if (currentEnv === "test" && data.notLogin) {
localStorage.setItem("ticket", "");
await this.getTicket(getTestEnvTicket);
this.getSkinsList(this.projectId);
} else if (currentEnv === "prod" && data.notLogin) {
// 如果是线上环境,则发送钉钉消息
sendDingTalk();
localStorage.setItem("prod_ticket", "");
this.$message({
message: "线上tickct失效,已给相关人员发送消息",
type: "info"
});
this.skinList = [];
return;
// sendDingTalk();
} else {
this.$message({
message: data.message,
type: "error"
});
this.skinList = [];
return;
}
}
} catch (e) {
this.skinList = [];
throw new Error(e.message);
}
},
hasIndex() {
const { skinList } = this;
return skinList.some(v => v.type === "1");
},
async saveSkins() {
const {
currentEnv,
skinId,
currentHtmlType,
currentTypes,
projectId,
tpl,
name,
skinList
} = this;
if (currentTypes === "2" && !skinId) {
this.$message({ message: "请选择修改的皮肤", type: "warning" });
return;
}
if (currentTypes === "1") {
if (this.hasIndex() && currentHtmlType === "1") {
this.$message({ message: "已存在首页", type: "warning" });
return;
} else if (!name) {
this.$message({ message: "请输入要添加的皮肤名称", type: "warning" });
return;
}
}
const data = {
projectId,
type: currentTypes,
currentHtmlType,
skinId,
tpl,
name,
env: currentEnv
};
const { ret } = await saveSkins(data);
if (ret.success !== false) {
this.$message({
message: `操作成功`,
type: "success"
});
} else {
this.$message({ message: ret.message, type: "error" });
}
// 新增皮肤则重新获取皮肤列表
if (currentTypes !== "2") {
// 2为修改,修改不需重新获取列表
this.getSkinsList(projectId);
} else if (currentTypes !== "3") {
this.name = "";
}
},
/** 获取访问链接 */
getUrl() {
const { currentHtmlType, currentEnv, skinId, projectId } = this;
const mapping = {
dev: "activity.m.duibadev.com.cn",
test: "activity.m.duibatest.com.cn",
prod: "https://activity.m.duiba.com.cn"
};
const url = `${mapping[currentEnv]}/projectx/${projectId}/${
currentHtmlType === "1" ? "index" : skinId
}.html`;
copy(url);
this.$message({
message: "链接复制成功",
type: "success"
});
},
async getTicket(fn, name = "ticket") {
let ticket = localStorage.getItem(name);
if (!ticket) {
ticket = await fn();
console.log(ticket, "ticketticket");
localStorage.setItem(name, ticket);
}
}
},
async mounted() {
const { projectxConfig } = this.project.data.options;
const projectId = projectxConfig[this.currentEnv];
this.projectId = projectId;
this.getSkinsList(projectId);
},
async created() {}
};
</script>
<style lang="scss">
.config {
display: flex;
.name {
display: inline-block;
width: 200px;
}
}
</style>
<template>
<div>
<div v-for="(item, index) in envConfig" :key="index">
<div class="list">
<span>{{ item.name }}</span>
<el-icon class="el-icon-connection" />
<el-input
size="small"
v-model="envs[item.key]"
:placeholder="`请输入${item.name}星速台项目ID`"
></el-input>
</div>
</div>
</div>
</template>
<script>
import { mapState, mapGetters, mapMutations } from "vuex";
import { clonePureObj } from "../../../../utils";
export default {
name: "ProjectxConfig",
data() {
return {
envConfig: [
{ key: "dev", name: "开发环境" },
{ key: "test", name: "测试环境" },
{ key: "prod", name: "线上环境" }
],
envs: {
dev: "",
test: "",
prod: ""
}
};
},
computed: {
...mapState(["project"])
},
created() {
this.envs = this.project.data.options.projectxConfig;
},
methods: {
...mapMutations(["modifyOptions"]),
edit() {
// this.editData = clonePureObj(this.options);
},
save() {
const { options } = this.project.data;
Object.assign(options, { projectxConfig: this.envs });
this.modifyOptions(options);
}
}
};
</script>
<style lang="scss" scoped>
.list {
display: flex;
align-items: center;
margin-bottom: 20px;
span {
width: 100px;
text-align: center;
}
i {
width: 50px;
}
> div {
width: 200px;
}
}
</style>
......@@ -12,7 +12,7 @@ module.exports = {
enableInSFC: true
}
},
/*devServer: {
devServer: {
host: '0.0.0.0',
port: '8080',
proxy: {
......@@ -22,8 +22,11 @@ module.exports = {
'/api': {
target: serverHost,
},
'polaris': {
target: serverHost
}
}
},*/
},
configureWebpack: {
plugins: [
new MonacoWebpackPlugin({
......
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