Lufaneng 9 months ago
parent b5e5a0f56f
commit c03f5b6f45

@ -14,25 +14,32 @@
<!-- 选择图纸模板 --> <!-- 选择图纸模板 -->
<view class="section"> <view class="section">
<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: 'flex', {
num: 2, type: 'flex',
gap: '20rpx', num: 2,
children: [{
type: 'custom',
num: 1,
gap: '20rpx', gap: '20rpx',
style: 'width: 300rpx;height:200rpx;marginLeft: 10rpx;' 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;',
}] },
}]"></uv-skeletons> {
type: 'custom',
num: 1,
gap: '20rpx',
style: 'width: 300rpx;height:200rpx;marginLeft: 10rpx;',
},
],
},
]"></uv-skeletons>
<view class="template-grid" v-else> <view class="template-grid" v-else>
<view class="template-item" :class="{ active: currentTemplate.id === item.id }" @click="selectTemplate(item)" v-for="item in templateList" :key="item.id"> <view class="template-item" :class="{ active: currentTemplate.id === 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>
@ -42,14 +49,19 @@
<!-- 设置参数 --> <!-- 设置参数 -->
<view class="section" v-if="has_access"> <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="params_loading" :loading="params_loading" :skeleton="[
type: 'line', {
num: 3, type: 'line',
gap: '20rpx' num: 3,
}]"></uv-skeletons> gap: '20rpx',
},
]"></uv-skeletons>
<view class="form" v-else> <view class="form" v-else>
<uv-form labelAlign="left" labelWidth="auto" labelPosition="left" :model="formField" :rules="rules" ref="form"> <uv-form labelAlign="left" labelWidth="auto" labelPosition="left" :model="formField" :rules="rules" 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.name" :label="item.name + ''" v-for="item in currentTemplate.params?.filter(
(item) => item.enabled
) || []">
<div class="required" v-if="item.required" style="color: #f12323;">*</div>
<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 @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-form-item> </uv-form-item>
<!-- <uv-form-item prop="password" label="载重kg"> <!-- <uv-form-item prop="password" label="载重kg">
@ -113,8 +125,8 @@
</view> </view>
<view class="section" v-else> <view class="section" v-else>
<div class="status">状态{{ currentTemplate.access_status }}</div> <div class="status">申请状态{{ get_access_status(currentTemplate.access_status) }}</div>
<uv-button text="申请权限" color="#3F70FF"></uv-button> <uv-button size="small" v-if="currentTemplate.access_status !== 'pending'" @click="openApplyModal" text="申请权限" color="#3F70FF"></uv-button>
</view> </view>
<!-- 底部按钮 --> <!-- 底部按钮 -->
@ -122,75 +134,171 @@
<uv-button :loading="generating" @click="modalRefOpen" 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-modal ref="applyModalRef" showCancelButton title="申请权限" @confirm="confirmApply" @cancel="cancelApply">
<view class="apply-modal-content">
<view class="apply-label">申请理由</view>
<uv-textarea v-model="applyReason" placeholder="请输入申请理由" maxlength="200" count></uv-textarea>
</view>
</uv-modal>
<uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker> <uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker>
</view> </view>
</template> </template>
<script setup> <script setup>
import { import { ref, onMounted } from "vue";
ref,
onMounted
} from "vue";
import { import {
onShow, onShow,
onLoad, onLoad,
onShareAppMessage, onShareAppMessage,
onShareTimeline, onShareTimeline,
onReachBottom, onReachBottom,
onPullDownRefresh onPullDownRefresh,
} from "@dcloudio/uni-app"; } from "@dcloudio/uni-app";
import { import { useAuthStore, useUserStore } from "@/store";
useAuthStore,
useUserStore
} from "@/store";
import RPC from "@/utils/request"; import RPC from "@/utils/request";
import { import { usePermission } from "@/hooks/usePermission";
usePermission
} from "@/hooks/usePermission";
const authStore = useAuthStore(); const authStore = useAuthStore();
const userStore = useUserStore(); const userStore = useUserStore();
const loading = ref(false) const loading = ref(false);
const params_loading = ref(false)
const has_access = ref(false)
const applyRef = ref(null) const has_access = ref(false);
const applyModalRef = ref(null);
const applyReason = ref("");
const applyLoading = ref(false);
const get_access_status = access_status => {
let str = ''
if (access_status === 'none') {
str = '无权限'
} else if (access_status === 'pending') {
str = '等待审批...'
} else if (access_status === 'rejected') {
str = '已拒绝'
} else if (access_status === 'approved') {
str = '已同意'
} else {
str = access_status
}
return str
}
const modalRefOpen = () => { const modalRefOpen = () => {
if(!has_access.value) { if (!has_access.value) {
uni.showToast({ uni.showToast({
title: "模板无权限使用", title: "模板无权限使用",
icon: "error", icon: "error",
}); });
return;
}
let flag = false
let name
currentTemplate.value.params
?.filter((item) => item.enabled)
.forEach((item) => {
if (item.required && !item.value) {
flag = true
name = item.name
}
});
if (flag) {
uni.showToast({
title: `请检查【${name}`,
icon: 'none'
})
return return
} }
modalRef.value.open() modalRef.value.open();
} };
const currentParams = ref(null) const currentParams = ref(null);
const openPicker = item => { const openPicker = (item) => {
console.log(item) console.log(item);
if (item.type !== 'select') return if (item.type !== "select") return;
currentParams.value = item currentParams.value = item;
columns.value = [item.options.split(',')] columns.value = [item.options.split(",")];
picker.value.open() picker.value.open();
} };
const picker = ref(null) const picker = ref(null);
const columns = ref([[]]) const columns = ref([[]]);
const confirm = val => { const confirm = (val) => {
console.log(val) console.log(val);
currentParams.value.value = val.value[0] currentParams.value.value = val.value[0];
} };
//
const openApplyModal = () => {
applyReason.value = "";
applyModalRef.value.open();
};
//
const confirmApply = async () => {
if (!applyReason.value.trim()) {
uni.showToast({
title: "请输入申请理由",
icon: "error",
});
return;
}
applyLoading.value = true;
try {
await RPC.post("/template_access_apply", {
template_id: currentTemplate.value.id,
reason: applyReason.value.trim(),
});
uni.showToast({
title: "申请已提交",
icon: "success",
});
applyModalRef.value.close();
applyReason.value = "";
getList()
} catch (error) {
uni.showToast({
title: "申请失败,请重试",
icon: "error",
});
} finally {
applyLoading.value = false;
}
};
//
const cancelApply = () => {
applyReason.value = "";
};
const generating = ref(false); const generating = ref(false);
const modalRef = ref(null) const modalRef = ref(null);
const confirmGenerate = () => { const confirmGenerate = () => {
const params = {} const params = {};
currentTemplate.value.params?.filter(item => item.enabled).forEach(item => { let flag = false
params[item.name] = item.value let name = ''
}) currentTemplate.value.params
RPC.post('/template_create_task', { template_id: currentTemplate.value.id, template_data: params }).then(() => { ?.filter((item) => item.enabled)
.forEach((item) => {
if (item.required && !item.value) {
flag = true
name = item.name
}
params[item.name] = item.value;
});
if (flag) {
uni.showToast({
title: `请检查【${name}`,
icon: 'none'
})
return
}
RPC.post("/template_create_task", {
template_id: currentTemplate.value.id,
template_data: params,
}).then(() => {
uni.showToast({ uni.showToast({
title: "图纸开始生成", title: "图纸开始生成",
icon: "success", icon: "success",
@ -199,29 +307,50 @@ const confirmGenerate = () => {
uni.navigateTo({ uni.navigateTo({
url: "/pagesA/generate-record/generate-record", url: "/pagesA/generate-record/generate-record",
}); });
}, 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_with_access', { RPC.post("/template/list_with_access", {
page: 1, page: 1,
limit: -1 limit: -1,
}).then(res => {
templateList.value = (res.rows || []).filter(item => item.enabled)
currentTemplate.value = templateList.value[0] ? JSON.parse(JSON.stringify(templateList.value[0])) : {}
}).finally(() => {
loading.value = false
}) })
} .then((res) => {
templateList.value = (res.rows || []).filter((item) => item.enabled);
currentTemplate.value = templateList.value[0]
? JSON.parse(JSON.stringify(templateList.value[0]))
: {};
if (currentTemplate.value.has_access) {
params_loading.value = true
has_access.value = true
RPC.post('/template/detail', { id: currentTemplate.value.id }).then(res => {
currentTemplate.value.params = res?.params
}).finally(() => {
params_loading.value = false
})
}
})
.finally(() => {
loading.value = false;
});
};
// //
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 has_access.value = currentTemplate.value.has_access;
if (currentTemplate.value.has_access) {
params_loading.value = true
RPC.post('/template/detail', { id: currentTemplate.value.id }).then(res => {
currentTemplate.value.params = res?.params
}).finally(() => {
params_loading.value = false
})
}
}; };
const form = ref(null); const form = ref(null);
@ -271,7 +400,7 @@ onLoad(() => {
console.log("index-onLoad"); console.log("index-onLoad");
}); });
onShow(async () => { onShow(async () => {
getList() 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 ? "已登录" : "跳转登录");
@ -282,7 +411,7 @@ onShow(async () => {
} }
}); });
onPullDownRefresh(() => { onPullDownRefresh(() => {
getList() getList();
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
}); });
</script> </script>
@ -345,6 +474,10 @@ onPullDownRefresh(() => {
color: #333; color: #333;
margin-bottom: 16px; margin-bottom: 16px;
} }
.status {
margin-bottom: 20px;
}
} }
.template-grid { .template-grid {
@ -413,6 +546,17 @@ onPullDownRefresh(() => {
/* H5环境下给tabBar留出空间 */ /* H5环境下给tabBar留出空间 */
/* #endif */ /* #endif */
} }
.apply-modal-content {
padding: 20px 0;
width: 100%;
.apply-label {
font-size: 14px;
color: #333;
margin-bottom: 12px;
}
}
</style> </style>
<style lang="scss"> <style lang="scss">

@ -8,7 +8,7 @@
<view class="record-item"> <view class="record-item">
<!-- 记录信息 --> <!-- 记录信息 -->
<view class="record-info"> <view class="record-info">
<view class="record-title">{{ record.file_name || record.order_no || record.plannedNo }}</view> <view class="record-title">{{ record.file_name || record.order_no + record.order_no || record.plannedNo }}</view>
<view class="record-time"> <view class="record-time">
生成时间: 生成时间:
{{ {{
@ -266,12 +266,16 @@
.record-info { .record-info {
flex: 1; flex: 1;
overflow: auto;
.record-title { .record-title {
width: 100%;
font-size: 16px; font-size: 16px;
color: #333; color: #333;
font-weight: 500; font-weight: 500;
margin-bottom: 6px; margin-bottom: 6px;
word-wrap: break-word;
white-space: normal;
} }
.record-time { .record-time {
@ -281,6 +285,7 @@
} }
.status-tag { .status-tag {
flex-shrink: 0;
padding: 4px 8px; padding: 4px 8px;
border-radius: 4px; border-radius: 4px;
font-size: 12px; font-size: 12px;

Loading…
Cancel
Save