Skip to content

Commit

Permalink
Merge pull request #599 from ielgnaw/lesscode-master
Browse files Browse the repository at this point in the history
feat: merge
  • Loading branch information
terlinhe authored Oct 15, 2021
2 parents 72a47ee + e8de1d2 commit f68ffb5
Show file tree
Hide file tree
Showing 244 changed files with 11,855 additions and 1,695 deletions.
2 changes: 1 addition & 1 deletion paas-ce/lesscode/lib/client/build/build-dll.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if (!(manifestExist & bundleExist)) {
},
extractComments: false,
cache: true,
parallel: true,
parallel: 2,
sourceMap: true
}),

Expand Down
2 changes: 1 addition & 1 deletion paas-ce/lesscode/lib/client/build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = merge(baseConf, {
},
extractComments: false,
cache: true,
parallel: true,
parallel: 2,
sourceMap: true
}),
new OptimizeCSSPlugin({
Expand Down
16 changes: 15 additions & 1 deletion paas-ce/lesscode/lib/client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
computed: {
...mapGetters(['mainContentLoading']),
emptyPage () {
return this.$route.name === 'preview'
return this.$route.name === 'preview' || this.$route.name === 'previewTemplate'
},
authed () {
return this.$route.meta.authed
Expand All @@ -74,6 +74,10 @@
}
},
async created () {
await this.$store.dispatch('isPlatformAdmin')
},
mounted () {
const platform = window.navigator.platform.toLowerCase()
if (platform.indexOf('win') === 0) {
Expand All @@ -100,6 +104,7 @@
#app {
width: 100%;
height: 100%;
overflow-y: hidden;
font-size: 14px;
color: #63656e;
}
Expand All @@ -117,4 +122,13 @@
/* font-family: Microsoft Yahei, PingFang SC, Helvetica, Aria; */
font-family: -apple-system, BlinkMacSystemFont, PingFang SC, Microsoft YaHei, Helvetica Neue, Arial;
}
.red-point {
display:block;
margin-left: 3px;
background:#f00;
border-radius:50%;
width:6px;
height:6px;
}
</style>
29 changes: 29 additions & 0 deletions paas-ce/lesscode/lib/client/src/common/constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const PROJECT_TEMPLATE_TYPE = [
{
id: 'OFFCIAL_WEBSITE',
name: '企业官网'
},
{
id: 'ADMIN_BACKEND',
name: '管理后台'
}
]

export const PAGE_TEMPLATE_TYPE = [
{
id: 'FORM',
name: '表单'
},
{
id: 'CHART',
name: '图表'
},
{
id: 'INFO',
name: '信息'
},
{
id: 'LAYOUT',
name: '布局'
}
]
128 changes: 128 additions & 0 deletions paas-ce/lesscode/lib/client/src/common/process-targetdata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// import store from '@/store'
import { walkGrid } from '@/common/util'
import { replaceFuncKeyword } from '@/components/methods/function-helper.js'

function getVarList (targetData, variableList = []) {
// 记录已使用的变量
const usedVariableMap = {}
function addUsedVariable (id, dir) {
const { modifiers, prop, type, val, valType, slot } = dir
function generateUseInfo (variableId) {
const useInfo = { type, componentId: id, prop, modifiers, val, slot }
const useInfos = (usedVariableMap[variableId] || (usedVariableMap[variableId] = [], usedVariableMap[variableId]))
useInfos.push(useInfo)
}
if (val !== '' && !(val.startsWith('form') && val.indexOf('.') > 0) && valType === 'variable') {
const variable = variableList.find((variable) => (variable.variableCode === val))
if (variable) {
generateUseInfo(variable.id)
}
}
if (val !== '' && valType === 'expression') {
variableList.forEach(({ variableCode, id }) => {
if (val.includes(variableCode)) generateUseInfo(id)
})
}
}

const callBack = (component) => {
const renderSlots = component.renderSlots || {}
Object.keys(renderSlots).forEach((key) => {
const { payload = {} } = renderSlots[key] || {}

if (payload.variableData && payload.variableData.val) {
const { val, valType } = payload.variableData
const dir = { slot: key, type: 'slots', val, valType }
addUsedVariable.call(this, component.componentId, dir)
}
})

const renderDirectives = component.renderDirectives || []
renderDirectives.forEach((dir) => {
addUsedVariable.call(this, component.componentId, dir)
})
}
targetData.forEach((grid, index) => walkGrid(targetData, grid, callBack, callBack, index))
const ids = Object.keys(usedVariableMap)
return ids.map(id => ({
id,
variableCode: usedVariableMap[id][0] && usedVariableMap[id][0].val
}))
}

function getFuncList (targetData = [], funcGroups = []) {
const usedFuncMap = {}
const findUsedFuncsByCode = (code) => {
if (typeof code === 'object') code = code.methodCode
if ([undefined, ''].includes(code)) return
funcGroups.forEach((group) => {
const functionList = group.functionList || []
const curFunc = functionList.find((x) => (x.funcCode === code))
if (curFunc) {
if (!usedFuncMap[curFunc.id]) {
usedFuncMap[curFunc.id] = curFunc
replaceFuncKeyword(curFunc.funcBody, (all, first, second, dirKey, funcStr, funcCode) => {
if (funcCode) findUsedFuncsByCode(funcCode)
})
}
}
})
}

const callBack = (component) => {
const renderProps = component.renderProps || {}
const isForm = component.type === 'widget-form'
Object.keys(renderProps).forEach((key) => {
const { type, payload, val } = renderProps[key] || {}

if (type === 'remote' || (Array.isArray(type) && type.includes('remote'))) {
if (payload && payload.methodCode) {
const code = payload.methodCode
findUsedFuncsByCode(code)
}
}

// form表单简要绑定函数
if (isForm && key === 'rules') {
Object.keys(val).forEach((ruleKey) => {
if (val[ruleKey] && val[ruleKey].length) {
val[ruleKey].map(item => {
if (item.type === 'validator' && item.validator) {
findUsedFuncsByCode(item.validator)
}
})
}
})
}
})

const renderSlots = component.renderSlots || {}
Object.keys(renderSlots).forEach((key) => {
const { type, payload = {} } = renderSlots[key] || {}

if (type === 'remote') {
if (payload && payload.methodData && payload.methodData.methodCode) {
findUsedFuncsByCode(payload.methodData.methodCode)
}
}
})

const renderEvents = component.renderEvents || {}
Object.keys(renderEvents).forEach((event) => {
const code = renderEvents[event]
if (code) findUsedFuncsByCode(code)
})
}
targetData.forEach((grid, index) => walkGrid(targetData, grid, callBack, callBack, index))

const funcIds = Object.keys(usedFuncMap)
return funcIds.map(id => ({
id,
funcCode: usedFuncMap[id].funcCode
}))
}

export default {
getVarList,
getFuncList
}
23 changes: 21 additions & 2 deletions paas-ce/lesscode/lib/client/src/common/targetData.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import store from '@/store'
import { uuid, walkGrid, findComponentParentGrid } from '@/common/util'
import { camelCase, camelCaseTransformMerge } from 'change-case'
import cloneDeep from 'lodash.clonedeep'

class TargetData {
constructor () {
this.targetData = store.getters['drag/targetData']
Expand Down Expand Up @@ -249,11 +249,30 @@ class TargetData {
return this
}

changeFormItemVmodel (data, oldId) {
const oldVModelName = `${camelCase(oldId, { transform: camelCaseTransformMerge })}model.`
const newVModelName = `${camelCase(data.componentId, { transform: camelCaseTransformMerge })}model.`
data.renderSlots.default.val.forEach(formItem => {
const item = formItem.renderSlots.default.val[0]
item.renderDirectives.forEach(directive => {
if (directive.type === 'v-model') {
directive.val = directive.val.replace(oldVModelName, newVModelName)
}
})
})
}

cloneNode (node, shouldChangeId) {
node = cloneDeep(node)
const callBack = (data) => {
if (shouldChangeId) data.componentId = data.componentId.replace(/.{8}$/, uuid())
const oldId = data.componentId

if (shouldChangeId) data.componentId = (data.componentId && data.componentId.replace(/.{8}$/, uuid()))
data.renderKey = uuid()

if (data.type === 'widget-form') {
this.changeFormItemVmodel(data, oldId)
}
}
if (Array.isArray(node)) {
node.forEach((grid, index) => {
Expand Down
10 changes: 10 additions & 0 deletions paas-ce/lesscode/lib/client/src/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export function walkGrid (children, grid, childCallBack, parentCallBack, index,
const slotKeys = Object.keys(renderSlots)
if (component.type === 'render-grid' || component.type === 'free-layout' || (component.name === 'dialog' && isLayoutSupportDialog)) { // 如果是旧数据dialog不做遍历新dialog支持layout插槽需要遍历
walkGrid(children, component, childCallBack, parentCallBack, index, columnIndex, grid)
} else if (Array.isArray(renderSlots.default && renderSlots.default.val)) {
childCallBack(component, children, index, grid, columnIndex)
if (renderSlots.default.val.length && renderSlots.default.val[0] && renderSlots.default.val[0].componentId) {
renderSlots.default.val.forEach((item, slotIndex) => {
walkGrid({}, item, childCallBack, childCallBack, slotIndex)
})
}
} else if (slotKeys.some(key => renderSlots[key].name === 'layout')) {
slotKeys.forEach((key) => {
const slot = renderSlots[key]
Expand Down Expand Up @@ -531,6 +538,9 @@ export function splitValueAndUnit (type, string) {
if (!string) {
return ''
}
if (typeof string !== 'string') {
string = string.toString()
}

// 支持小数和负数
const reg = /^(-?\d+(\.\d+)?)(\D*)$/
Expand Down
11 changes: 10 additions & 1 deletion paas-ce/lesscode/lib/client/src/components/dynamic-tag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@
return {
isAddTag: false,
userInput: '',
defaultTags: [...this.value]
defaultTags: []
}
},
watch: {
value: {
handler () {
this.defaultTags = [...this.value]
},
immediate: true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
data () {
return {
objRule: {
validator: (val) => {
validator: (val = '') => {
try {
const Fn = Function
const replaceVal = val.replace(/\{\{([^\}]+)\}\}/g, (all, code) => `this.${code}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
const { id, ...rest } = this.marketFuncs.find((func) => (func.id === funcId)) || {}
const copyVaule = JSON.parse(JSON.stringify(this.form))
Object.assign(copyVaule, rest)
this.$emit('update:formChanged', true)
this.$parent.formChanged = true
this.$emit('update:form', copyVaule)
bus.$emit('switch-fun-form', copyVaule)
}
Expand Down
Loading

0 comments on commit f68ffb5

Please sign in to comment.