Lufaneng 9 months ago
parent 7e2a9e7594
commit b5e5a0f56f

@ -19,7 +19,8 @@
"path": "pages/index/index", "path": "pages/index/index",
"needLogin": true, "needLogin": true,
"style": { "style": {
"navigationBarTitleText": "电梯图纸生成平台" "navigationBarTitleText": "电梯图纸生成平台",
"enablePullDownRefresh":true
} }
}, },
{ {

@ -18,12 +18,12 @@
type: 'flex', type: 'flex',
num: 2, num: 2,
gap: '20rpx', gap: '20rpx',
children:[{ children: [{
type: 'custom', type: 'custom',
num: 1, num: 1,
gap: '20rpx', gap: '20rpx',
style: 'width: 300rpx;height:200rpx;marginLeft: 10rpx;' style: 'width: 300rpx;height:200rpx;marginLeft: 10rpx;'
},{ }, {
type: 'custom', type: 'custom',
num: 1, num: 1,
gap: '20rpx', gap: '20rpx',
@ -31,17 +31,16 @@
}] }]
}]"></uv-skeletons> }]"></uv-skeletons>
<view class="template-grid" v-else> <view class="template-grid" v-else>
<view class="template-item" :class="{ active: currentTemplate.id === item.id }" <view class="template-item" :class="{ active: currentTemplate.id === item.id }" @click="selectTemplate(item)" v-for="item in templateList" :key="item.id">
@click="selectTemplate(item)" v-for="item in templateList" :key="item.id"> <view class="tag" v-if="item.price_cents">¥ {{ item.price_cents / 100 }}</view>
<view class="tag" v-if="item.price_cents">¥ {{item.price_cents / 100}}</view> <view class="template-name">{{ item.name }}</view>
<view class="template-name">{{item.name}}</view> <view class="template-desc">{{ item.description }}</view>
<view class="template-desc">{{item.description}}</view>
</view> </view>
</view> </view>
</view> </view>
<!-- 设置参数 --> <!-- 设置参数 -->
<view class="section"> <view class="section" v-if="has_access">
<view class="section-title">设置参数</view> <view class="section-title">设置参数</view>
<uv-skeletons v-if="loading" :loading="loading" :skeleton="[{ <uv-skeletons v-if="loading" :loading="loading" :skeleton="[{
type: 'line', type: 'line',
@ -49,11 +48,9 @@
gap: '20rpx' gap: '20rpx'
}]"></uv-skeletons> }]"></uv-skeletons>
<view class="form" v-else> <view class="form" v-else>
<uv-form labelAlign="left" labelWidth="auto" labelPosition="left" :model="formField" :rules="rules" <uv-form labelAlign="left" labelWidth="auto" labelPosition="left" :model="formField" :rules="rules" ref="form">
ref="form"> <uv-form-item :prop="item.name" :label="item.name + ''" v-for="item in (currentTemplate.params?.filter(item => item.enabled) || [])">
<uv-form-item :prop="item.key" :label="item.name + ''" v-for="item in (currentTemplate.params?.filter(item => item.enabled) || [])"> <uv-input @click="openPicker(item)" :readonly="item.type === 'select'" :type="item.type === 'number' ? 'digit' : 'text'" v-model="item.value" color="#000" border="bottom" :placeholderStyle="{ color: '#666778' }" placeholder="请输入"></uv-input>
<uv-input :type="item.type === 'number' ? 'digit' : 'text'" v-model="item.value" color="#000"
border="bottom" :placeholderStyle="{ color: '#666778' }" placeholder="请输入"></uv-input>
</uv-form-item> </uv-form-item>
<!-- <uv-form-item prop="password" label="载重kg"> <!-- <uv-form-item prop="password" label="载重kg">
<uv-input <uv-input
@ -115,48 +112,84 @@
</view> </view>
</view> </view>
<view class="section" v-else>
<div class="status">状态{{ currentTemplate.access_status }}</div>
<uv-button text="申请权限" color="#3F70FF"></uv-button>
</view>
<!-- 底部按钮 --> <!-- 底部按钮 -->
<view class="bottom-actions"> <view class="bottom-actions">
<uv-button :loading="generating" @click="() => modalRef.open()" text="生成图纸" color="#3F70FF"></uv-button> <uv-button :loading="generating" @click="modalRefOpen" text="生成图纸" color="#3F70FF"></uv-button>
<uv-button @click="viewHistory" text="查看记录"></uv-button> <uv-button @click="viewHistory" text="查看记录"></uv-button>
</view> </view>
<uv-modal ref="modalRef" showCancelButton content='确定生成图纸?' @confirm="confirmGenerate"></uv-modal> <uv-modal ref="modalRef" showCancelButton content='确定生成图纸?' @confirm="confirmGenerate"></uv-modal>
<uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker>
</view> </view>
</template> </template>
<script setup> <script setup>
import { import {
ref, ref,
onMounted onMounted
} from "vue"; } from "vue";
import { import {
onShow, onShow,
onLoad, onLoad,
onShareAppMessage, onShareAppMessage,
onShareTimeline, onShareTimeline,
onReachBottom, onReachBottom,
} from "@dcloudio/uni-app"; onPullDownRefresh
import { } from "@dcloudio/uni-app";
import {
useAuthStore, useAuthStore,
useUserStore useUserStore
} from "@/store"; } from "@/store";
import RPC from "@/utils/request"; import RPC from "@/utils/request";
import { import {
usePermission usePermission
} from "@/hooks/usePermission"; } from "@/hooks/usePermission";
const authStore = useAuthStore();
const userStore = useUserStore();
const loading = ref(false)
const authStore = useAuthStore(); const has_access = ref(false)
const userStore = useUserStore(); const applyRef = ref(null)
const loading = ref(false)
const modalRefOpen = () => {
if(!has_access.value) {
uni.showToast({
title: "模板无权限使用",
icon: "error",
});
return
}
modalRef.value.open()
}
const generating = ref(false); const currentParams = ref(null)
const modalRef = ref(null) const openPicker = item => {
const confirmGenerate = () => { console.log(item)
if (item.type !== 'select') return
currentParams.value = item
columns.value = [item.options.split(',')]
picker.value.open()
}
const picker = ref(null)
const columns = ref([[]])
const confirm = val => {
console.log(val)
currentParams.value.value = val.value[0]
}
const generating = ref(false);
const modalRef = ref(null)
const confirmGenerate = () => {
const params = {} const params = {}
currentTemplate.value.params?.filter(item => item.enabled).forEach(item => { currentTemplate.value.params?.filter(item => item.enabled).forEach(item => {
params[item.name] = item.value params[item.name] = item.value
}) })
RPC.post('/template_create_task', {template_id:currentTemplate.value.id,template_data:params}).then(() => { RPC.post('/template_create_task', { template_id: currentTemplate.value.id, template_data: params }).then(() => {
uni.showToast({ uni.showToast({
title: "图纸开始生成", title: "图纸开始生成",
@ -169,12 +202,12 @@
}, 1000) }, 1000)
modalRef.value.close() modalRef.value.close()
}) })
} }
const templateList = ref([]) const templateList = ref([])
const currentTemplate = ref({}) const currentTemplate = ref({})
const getList = () => { const getList = () => {
loading.value = true loading.value = true
RPC.post('/template/list', { RPC.post('/template/list_with_access', {
page: 1, page: 1,
limit: -1 limit: -1
}).then(res => { }).then(res => {
@ -183,20 +216,20 @@
}).finally(() => { }).finally(() => {
loading.value = false loading.value = false
}) })
} }
getList()
// //
const selectTemplate = (item) => { const selectTemplate = (item) => {
currentTemplate.value = JSON.parse(JSON.stringify(item)); currentTemplate.value = JSON.parse(JSON.stringify(item));
}; has_access.value = currentTemplate.value.has_access
};
const form = ref(null); const form = ref(null);
const formField = ref({ const formField = ref({
phone: "", phone: "",
password: "", password: "",
}); });
const rules = ref({ const rules = ref({
// 'phone': { // 'phone': {
// required: true, // required: true,
// message: '', // message: '',
@ -207,37 +240,38 @@
// message: '', // message: '',
// trigger: ['blur', 'change'] // trigger: ['blur', 'change']
// } // }
}); });
// //
const viewHistory = () => { const viewHistory = () => {
uni.navigateTo({ uni.navigateTo({
url: "/pagesA/generate-record/generate-record", url: "/pagesA/generate-record/generate-record",
}); });
}; };
// //
onShareAppMessage((data) => { onShareAppMessage((data) => {
console.log("🚀 ~ onShareAppMessage ~ data:", data); console.log("🚀 ~ onShareAppMessage ~ data:", data);
return { return {
title: "电梯图纸生成平台", title: "电梯图纸生成平台",
path: "/pages/index/index", path: "/pages/index/index",
}; };
}); });
// //
onShareTimeline((data) => { onShareTimeline((data) => {
console.log("🚀 ~ onShareTimeline ~ data:", data); console.log("🚀 ~ onShareTimeline ~ data:", data);
return { return {
title: "电梯图纸生成平台", title: "电梯图纸生成平台",
query: "a=1&b=2", query: "a=1&b=2",
}; };
}); });
onLoad(() => { onLoad(() => {
console.log("index-onLoad"); console.log("index-onLoad");
}); });
onShow(async () => { onShow(async () => {
getList()
console.log("test page onShow"); console.log("test page onShow");
const hasPermission = await usePermission(); const hasPermission = await usePermission();
console.log(hasPermission ? "已登录" : "跳转登录"); console.log(hasPermission ? "已登录" : "跳转登录");
@ -246,11 +280,15 @@
authStore.signOut(); authStore.signOut();
uni.$uv.route("/pages/login/login"); uni.$uv.route("/pages/login/login");
} }
}); });
onPullDownRefresh(() => {
getList()
uni.stopPullDownRefresh();
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.container { .container {
font-size: 14px; font-size: 14px;
min-height: 100vh; min-height: 100vh;
background-color: #f8f8f8; background-color: #f8f8f8;
@ -260,9 +298,9 @@
padding-bottom: 102px; padding-bottom: 102px;
/* H5环境下需要更多空间 (50px按钮 + 50px tabBar + 2px间距) */ /* H5环境下需要更多空间 (50px按钮 + 50px tabBar + 2px间距) */
/* #endif */ /* #endif */
} }
.header-section { .header-section {
position: relative; position: relative;
height: 200px; height: 200px;
overflow: hidden; overflow: hidden;
@ -293,9 +331,9 @@
font-size: 12px; font-size: 12px;
} }
} }
} }
.section { .section {
margin: 16px; margin: 16px;
background: white; background: white;
border-radius: 12px; border-radius: 12px;
@ -307,9 +345,9 @@
color: #333; color: #333;
margin-bottom: 16px; margin-bottom: 16px;
} }
} }
.template-grid { .template-grid {
display: grid; display: grid;
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
gap: 12px; gap: 12px;
@ -323,6 +361,7 @@
text-align: center; text-align: center;
transition: all 0.3s; transition: all 0.3s;
position: relative; position: relative;
.tag { .tag {
position: absolute; position: absolute;
top: 0px; top: 0px;
@ -351,9 +390,9 @@
color: #999; color: #999;
} }
} }
} }
.bottom-actions { .bottom-actions {
z-index: 999; z-index: 999;
position: fixed; position: fixed;
bottom: 0; bottom: 0;
@ -373,13 +412,13 @@
bottom: 50px; bottom: 50px;
/* H5环境下给tabBar留出空间 */ /* H5环境下给tabBar留出空间 */
/* #endif */ /* #endif */
} }
</style> </style>
<style lang="scss"> <style lang="scss">
.bottom-actions { .bottom-actions {
.uv-button-wrapper { .uv-button-wrapper {
width: 48%; width: 48%;
} }
} }
</style> </style>
Loading…
Cancel
Save