增加手机端单表代码生成模板

This commit is contained in:
thinkgem
2024-11-05 11:25:53 +08:00
parent 80b397e9e4
commit a2ffa1e47a
5 changed files with 517 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013-Now http://jeesite.com All rights reserved.
No deletion without permission, or be held responsible to law. -->
<template>
<name>http.api.js</name>
<filePath>${frontDir}/common</filePath>
<fileName>http.api.${className}.js</fileName>
<content><![CDATA[
const install = (Vue, vm) => {
vm.$u.api = {
// 请将以下 ${functionName} 代码,复制到 http.api.js 文件中
// ${functionName} 开始
${className}: {
form: (params = {}) => vm.$u.post(config.adminPath+'/${urlPrefix}/form', params),
list: (params = {}) => vm.$u.post(config.adminPath+'/${urlPrefix}/listData', params),
save: (params = {}) => vm.$u.postJson(config.adminPath+'/${urlPrefix}/save', params),
<% if(toBoolean(table.optionMap['isHaveDisableEnable'])){ %>
disable: (params = {}) => vm.$u.post(config.adminPath+'/${urlPrefix}/disable', params),
enable: (params = {}) => vm.$u.post(config.adminPath+'/${urlPrefix}/enable', params),
<% } %>
delete: (params = {}) => vm.$u.post(config.adminPath+'/${urlPrefix}/delete', params),
},
// ${functionName} 结束
};
}
export default {
install
}
]]>
</content>
</template>

View File

@@ -0,0 +1,282 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013-Now http://jeesite.com All rights reserved.
No deletion without permission, or be held responsible to law. -->
<template>
<name>form.vue</name>
<filePath>${frontDir}/pages/${urlPrefix}</filePath>
<fileName>form.vue</fileName>
<content><![CDATA[
<template>
<view class="wrap">
<u-form class="form" :model="model" :rules="rules" ref="uForm" label-position="left">
<%
var userselectExists = false;
var officeselectExists = false;
var companyselectExists = false;
var areaselectExists = false;
for(c in table.columnList){
if(c.isQuery == "1" && !c.isTreeEntityColumn){
if(c.showType == 'userselect'){
userselectExists = true;
}else if(c.showType == 'officeselect'){
officeselectExists = true;
}else if(c.showType == 'companyselect'){
companyselectExists = true;
}else if(c.showType == 'areaselect'){
areaselectExists = true;
}
}
}
%>
<%
for (c in table.columnList){
if (c.isEdit == '1' && c.showType != 'hidden'){
// 如果是树结构的字段,则自动忽略
if(table.isTreeEntity && @StringUtils.inString(c.columnName, 'parent_code',
'parent_codes', 'tree_sorts', 'tree_leaf', 'tree_level', 'tree_names')
&& c.attrName != table.treeViewCodeAttrName
&& c.attrName != table.treeViewNameAttrName){
continue;
}
%>
<% if(c.showType == 'input'){ %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<u-input placeholder="请输入${c.columnLabel}" v-model="model.${c.attrName}" type="text" maxlength="${c.dataLength}"></u-input>
</u-form-item>
<% }else if(c.showType == 'textarea'){ %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180" label-position="top">
<u-input type="textarea" placeholder="请输入${c.columnLabel}" v-model="model.testTextarea" height="100" maxlength="${c.dataLength}" />
</u-form-item>
<% }else if(c.showType == 'select' || c.showType == 'select_multiple'){
var isMultiple = (c.showType == 'select_multiple'); %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<js-select v-model="model.${c.attrName}" dict-type="${c.optionMap['dictType']}"<% if(isMultiple){ %> multiple="true"<% } %> placeholder="请选择${c.columnLabel}"></js-select>
</u-form-item>
<% }else if(c.showType == 'radio'){ %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<js-radio v-model="model.${c.attrName}" dict-type="${c.optionMap['dictType']}"></js-radio>
</u-form-item>
<% }else if(c.showType == 'checkbox'){ %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<js-checkbox v-model="model.${c.attrName}" dict-type="${c.optionMap['dictType']}"></js-checkbox>
</u-form-item>
<% }else if(c.showType == 'date' || c.showType == 'datetime'){
var isTime = (c.showType == 'datetime'); %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<u-input placeholder="请输入${c.columnLabel}" v-model="model.${c.attrName}" format="yyyy-MM-dd${isTime?' HH:mm':''}" type="text" maxlength="${c.dataLength}"></u-input>
</u-form-item>
<% }else if(c.showType == 'userselect'){ %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<js-select v-model="model.${c.attrName}" :items="${c.attrName}List" placeholder="请选择${c.columnLabel}" :tree="true"<% if (isNotBlank(c.attrName2)){ %>
:label-value="model.${c.attrName2}" @label-input="model.${c.attrName2} = $event"<% } %>></js-select>
</u-form-item>
<% }else if(c.showType == 'officeselect'){ %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<js-select v-model="model.${c.attrName}" :items="${c.attrName}List" placeholder="请选择${c.columnLabel}" :tree="true"<% if (isNotBlank(c.attrName2)){ %>
:label-value="model.${c.attrName2}" @label-input="model.${c.attrName2} = $event"<% } %>></js-select>
</u-form-item>
<% }else if(c.showType == 'companyselect'){ %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<js-select v-model="model.${c.attrName}" :items="${c.attrName}List" placeholder="请选择${c.columnLabel}" :tree="true"<% if (isNotBlank(c.attrName2)){ %>
:label-value="model.${c.attrName2}" @label-input="model.${c.attrName2} = $event"<% } %>></js-select>
</u-form-item>
<% }else if(c.showType == 'areaselect'){ %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<js-select v-model="model.${c.attrName}" :items="${c.attrName}List" placeholder="请选择${c.columnLabel}" :tree="true"<% if (isNotBlank(c.attrName2)){ %>
:label-value="model.${c.attrName2}" @label-input="model.${c.attrName2} = $event"<% } %>></js-select>
</u-form-item>
<% }else{ %>
<u-form-item label="${c.columnLabel}" prop="${c.attrName}" label-width="180">
<u-input placeholder="请输入${c.columnLabel}" v-model="model.${c.attrName}" type="text" maxlength="${c.dataLength}"></u-input>
</u-form-item>
<% } %>
<%
}
}
%>
<% if(toBoolean(table.optionMap['isImageUpload'])){ %>
<u-form-item label="上传图片" prop="images" label-position="top">
<js-uploadfile v-model="model.dataMap" :biz-key="model.id" biz-type="${className}_image"></js-uploadfile>
</u-form-item>
</u-form>
<% } %>
<view class="form-footer">
<u-button class="btn" type="primary" @click="submit">提交</u-button>
<!-- <u-button class="btn" type="default" @click="cancel">关闭</u-button> -->
</view>
</view>
</template>
<script>
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
export default {
data() {
return {
model: {
id: '',
<%
for (c in table.columnList){
if (c.isEdit == '1' && c.showType != 'hidden'){
// 如果是树结构的字段,则自动忽略
if(table.isTreeEntity && @StringUtils.inString(c.columnName, 'parent_code',
'parent_codes', 'tree_sorts', 'tree_leaf', 'tree_level', 'tree_names')
&& c.attrName != table.treeViewCodeAttrName
&& c.attrName != table.treeViewNameAttrName){
continue;
}
%>
<% if(c.showType == 'userselect'){ %>
${c.simpleAttrName}: {
userCode: '',
userName: ''
},
<% }else if(c.showType == 'officeselect'){ %>
${c.simpleAttrName}: {
officeCode: '',
officeName: ''
},
<% }else if(c.showType == 'companyselect'){ %>
${c.simpleAttrName}: {
companyCode: '',
companyName: ''
},
<% }else if(c.showType == 'areaselect'){ %>
${c.simpleAttrName}: {
areaCode: '',
areaName: ''
},
<% }else{ %>
${c.attrName}: '',
<% } %>
<%
}
}
%>
},
rules: {
<%
for (c in table.columnList){
if (c.isEdit == '1' && c.showType != 'hidden'){
// 如果是树结构的字段,则自动忽略
if(table.isTreeEntity && @StringUtils.inString(c.columnName, 'parent_code',
'parent_codes', 'tree_sorts', 'tree_leaf', 'tree_level', 'tree_names')
&& c.attrName != table.treeViewCodeAttrName
&& c.attrName != table.treeViewNameAttrName){
continue;
}
%>
<% if(c.isRequired == '1'){ %>
'${c.attrName}': [
{
required: true,
message: '请输入${c.columnLabel}',
trigger: ['change','blur'],
}
],
<% } %>
<%
}
}
%>
},
<%
for (c in table.columnList){
if (c.isEdit == '1' && c.showType != 'hidden'){
// 如果是树结构的字段,则自动忽略
if(table.isTreeEntity && @StringUtils.inString(c.columnName, 'parent_code',
'parent_codes', 'tree_sorts', 'tree_leaf', 'tree_level', 'tree_names')
&& c.attrName != table.treeViewCodeAttrName
&& c.attrName != table.treeViewNameAttrName){
continue;
}
%>
<% if(c.showType == 'userselect'){ %>
${c.simpleAttrName}List: [],
<% }else if(c.showType == 'officeselect'){ %>
${c.simpleAttrName}List: [],
<% }else if(c.showType == 'companyselect'){ %>
${c.simpleAttrName}List: [],
<% }else if(c.showType == 'areaselect'){ %>
${c.simpleAttrName}List: [],
<% } %>
<%
}
}
%>
};
},
onLoad(params){
this.$u.api.${className}.form(params).then(res => {
Object.assign(this.model, res.${className});
this.$refs.uForm.setRules(this.rules);
<%
for (c in table.columnList){
if (c.isEdit == '1' && c.showType != 'hidden'){
// 如果是树结构的字段,则自动忽略
if(table.isTreeEntity && @StringUtils.inString(c.columnName, 'parent_code',
'parent_codes', 'tree_sorts', 'tree_leaf', 'tree_level', 'tree_names')
&& c.attrName != table.treeViewCodeAttrName
&& c.attrName != table.treeViewNameAttrName){
continue;
}
%>
<% if(c.showType == 'userselect'){ %>
this.$u.api.office.treeData({isLoadUser: true}).then(res => {
this.${c.simpleAttrName}List = res;
});
<% }else if(c.showType == 'officeselect'){ %>
this.$u.api.office.treeData().then(res => {
this.${c.simpleAttrName}List = res;
});
<% }else if(c.showType == 'companyselect'){ %>
this.$u.api.company.treeData().then(res => {
this.${c.simpleAttrName}List = res;
});
<% }else if(c.showType == 'areaselect'){ %>
this.$u.api.area.treeData().then(res => {
this.${c.simpleAttrName}List = res;
});
<% } %>
<%
}
}
%>
});
},
methods: {
submit() {
this.$refs.uForm.validate(valid => {
if (valid) {
// console.log('${className}-save: ' + JSON.stringify(this.model));
this.$u.api.${className}.save(this.model).then(res => {
uni.showModal({
title: '提示',
content: res.message,
showCancel: false,
success: function () {
if (res.result == 'true') {
uni.setStorageSync('refreshList', true);
uni.navigateBack();
}
}
});
});
} else {
this.$u.toast('您填写的信息有误,请根据提示修正。');
}
});
},
cancel() {
uni.navigateBack();
}
}
};
</script>
<style lang="scss">
</style>
<% %>
]]>
</content>
</template>

View File

@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013-Now http://jeesite.com All rights reserved.
No deletion without permission, or be held responsible to law. -->
<template>
<name>list.vue</name>
<filePath>${frontDir}/pages/${urlPrefix}</filePath>
<fileName>list.vue</fileName>
<content><![CDATA[
<template>
<view class="wrap">
<view class="search">
<u-search v-model="keywords" @custom="search" @search="search"></u-search>
</view>
<scroll-view class="scroll-list" scroll-y="true" @scrolltolower="loadMore">
<u-cell-group class="list" :border="false">
<u-swipe-action :options="options" v-for="(item, index) in list" :key="item.id" :index="index" @click="optionsClick">
<%
var idParam = '', idParam2 = '';
for(pk in table.pkList){
idParam = idParam + (pk.attrName + '=\'+item.' + pk.attrName);
idParam2 = idParam2 + ('item.' + pk.attrName);
if (pkLP.index != table.pkList.~size) {
idParam = idParam + '&';
idParam2 = idParam2 + ' || ';
}
}
for(c in table.columnList){
if(c.isList == "1"){
// 如果是树结构的字段,则自动忽略
if(table.isTreeEntity && @StringUtils.inString(c.columnName, 'parent_code',
'parent_codes', 'tree_sorts', 'tree_leaf', 'tree_level', 'tree_names')
&& c.attrName != table.treeViewCodeAttrName
&& c.attrName != table.treeViewNameAttrName){
continue;
}
%>
<u-cell-item :arrow="true" @click="navTo('form?${idParam})">
<text slot="title">{{item.${c.attrName} || ${idParam2}}}</text>
<text slot="label">创建者:{{item.createBy}} &nbsp;|&nbsp; 时间:{{item.createDate}}</text>
</u-cell-item>
<%
break;
}
}
%>
</u-swipe-action>
</u-cell-group>
<view class="loadmore" @click="loadMore">
<u-loadmore :status="loadStatus"></u-loadmore>
</view>
</scroll-view>
<view class="btn-plus" @click="navTo('form')">
<u-icon name="plus-circle-fill" size="90" color="#3d87ff"></u-icon>
</view>
</view>
</template>
<script>
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
export default {
data() {
return {
keywords: '',
query: {
pageNo: 1,
pageSize: 20
},
list: [],
count: 0,
loadStatus: 'loadmore',
options: [
{text: '上传', style: { background: '#414ee0'}},
{text: '删除', style: { background: '#dd524d'}}
]
};
},
onLoad() {
this.loadList();
},
onShow() {
if (uni.getStorageSync('refreshList') === true){
uni.removeStorageSync('refreshList');
this.search('');
}
},
methods: {
loadMore() {
this.loadStatus = "loading";
setTimeout(() => {
this.query.pageNo += 1;
this.loadList();
}, 100);
},
loadList() {
this.$u.api.${className}.list(this.query).then(res => {
if (!res.list || res.list.length == 0){
this.loadStatus = "nomore";
return;
}
this.list = this.list.concat(res.list);
this.count = res.count;
this.query.pageNo = res.pageNo;
this.query.pageSize = res.pageSize;
this.loadStatus = "loadmore";
});
},
optionsClick(rowIndex, btnIndex) {
let self = this, row = self.list[rowIndex];
if(btnIndex == 0) {
this.navTo('formUpload?id='+row.id);
} else if(btnIndex == 1) {
uni.showModal({
title: '提示',
content: '确认要删除该数据吗?',
showCancel: true,
success: function (res2) {
if (res2.confirm) {
self.$u.api.${className}.delete({id: row.id}).then(res => {
self.$u.toast(res.message);
if (res.result == 'true'){
self.list.splice(rowIndex, 1);
}
});
}
}
});
}
},
search(value) {
this.list = [];
this.query.pageNo = 0;
this.query.testInput = value;
this.loadList();
},
navTo(url) {
uni.navigateTo({
url: url
});
}
}
};
</script>
<style lang="scss">
page {
background-color: #f8f8f8;
}
.btn-plus {
position: absolute;
bottom: 50rpx;
right: 50rpx;
z-index: 1;
opacity: 0.6;
}
.btn-plus:hover {
opacity: 1;
}
</style>
<% %>
]]>
</content>
</template>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013-Now http://jeesite.com All rights reserved.
No deletion without permission, or be held responsible to law. -->
<template>
<name>pages.json</name>
<filePath>${frontDir}</filePath>
<fileName>pages.${className}.json</fileName>
<content><![CDATA[
{
"pages": [
/* 请将以下 ${functionName} 代码,复制到 pages.json 文件中 */
/* ${functionName} 开始 */
{
"path": "pages/${className}/form",
"style": {
"navigationBarTitleText": "新增编辑"
}
},
{
"path": "pages/${className}/list",
"style": {
"navigationBarTitleText": "${functionName}"
}
},
/* ${functionName} 结束 */
],
}
]]>
</content>
</template>

View File

@@ -170,6 +170,12 @@
<template>query/dao.xml</template> <template>query/dao.xml</template>
</childTable> </childTable>
</category> </category>
<category value="crud_only_app" label="手机端列表和表单单表App">
<template>app/appApi.xml</template>
<template>app/appList.xml</template>
<template>app/appForm.xml</template>
<template>app/appPages.xml</template>
</category>
</tplCategory> </tplCategory>
<!-- 属性类型 --> <!-- 属性类型 -->
<attrType> <attrType>