提交 c6039576 作者: guolinhua

feat:新增农场查询,添加;新增发送作业需求请求功能

上级 83f41262
# API 接口地址 # API 接口地址
VITE_GLOB_API_URL=http://111.22.182.169:49600 # VITE_GLOB_API_URL=http://111.22.182.169:49600
# VITE_GLOB_API_URL=http://36.133.16.81:42111 VITE_GLOB_API_URL=http://36.133.16.81:42111
# API 接口地址前缀 # API 接口地址前缀
VITE_GLOB_API_URL_PREFIX=/jeecgboot # VITE_GLOB_API_URL_PREFIX=/jeecgboot
VITE_GLOB_API_URL_PREFIX=/jeecg-boot
...@@ -2,14 +2,16 @@ ...@@ -2,14 +2,16 @@
import { onExit } from '@dcloudio/uni-app' import { onExit } from '@dcloudio/uni-app'
import { isDevMode } from '@/utils/env' import { isDevMode } from '@/utils/env'
import { usePermissions } from '@/hooks/app/usePermissions' import { usePermissions } from '@/hooks/app/usePermissions'
import { useDictStore } from '@/store/modules/dict'
// import * as Push from '@/utils/push' // import * as Push from '@/utils/push'
const dictStore = useDictStore()
// 监听权限获取 // 监听权限获取
const { listen: startPermissionListener, stop: stopPermissionListener } = usePermissions() const { listen: startPermissionListener, stop: stopPermissionListener } = usePermissions()
onLaunch(() => { onLaunch(() => {
console.log('App Launch') console.log('App Launch')
dictStore.setDictList()
// 监听权限获取 // 监听权限获取
startPermissionListener() startPermissionListener()
......
...@@ -2,6 +2,8 @@ import { otherHttp } from '/@/utils/http/axios' ...@@ -2,6 +2,8 @@ import { otherHttp } from '/@/utils/http/axios'
enum Api { enum Api {
zoneList = '/online/cgform/api/getData/01fd687ecb164aea914e92047e144d66', // 功能菜单数据 zoneList = '/online/cgform/api/getData/01fd687ecb164aea914e92047e144d66', // 功能菜单数据
farmsList = '/farms/list', // 农场列表
farmsAdd = '/farms/add', // 添加农场
agricultureModelsList = '/online/cgform/api/getData/7b2983df6ddf416aba68db8b0ab234ab', // 农业模型数据 agricultureModelsList = '/online/cgform/api/getData/7b2983df6ddf416aba68db8b0ab234ab', // 农业模型数据
baseManagementList = '/online/cgform/api/getData/e4e4e6c901254b60b1e7a005097999ec', // 基地管理数据 baseManagementList = '/online/cgform/api/getData/e4e4e6c901254b60b1e7a005097999ec', // 基地管理数据
commonToolsList = '/online/cgform/api/getData/3a7fbb877f304b7d83935caa454859c4', // 常用工具数据 commonToolsList = '/online/cgform/api/getData/3a7fbb877f304b7d83935caa454859c4', // 常用工具数据
...@@ -20,6 +22,28 @@ export function zoneList(params = {}) { ...@@ -20,6 +22,28 @@ export function zoneList(params = {}) {
/** /**
* @param params 请求参数 * @param params 请求参数
* @description: 农场列表
*/
export function farmsList(params = {}) {
return otherHttp.get({
url: Api.farmsList,
params,
})
}
/**
* @param params 请求参数
* @description: 添加农场
*/
export function farmsAdd(params = {}) {
return otherHttp.post({
url: Api.farmsAdd,
params,
})
}
/**
* @param params 请求参数
* @description: 农业模型数据 * @description: 农业模型数据
*/ */
export function agricultureModelsList(params = {}) { export function agricultureModelsList(params = {}) {
......
...@@ -7,6 +7,7 @@ enum Api { ...@@ -7,6 +7,7 @@ enum Api {
farmMachineAddMachine = '/farmMachine/machineWork/app/addMachine', // 发布农机服务 farmMachineAddMachine = '/farmMachine/machineWork/app/addMachine', // 发布农机服务
farmMachineAddFarm = '/farmMachine/machineWork/app/addFarm', // 发布农活服务 farmMachineAddFarm = '/farmMachine/machineWork/app/addFarm', // 发布农活服务
farmMachineEdit = '/farmMachine/machineWork/edit', // 编辑农机服务 farmMachineEdit = '/farmMachine/machineWork/edit', // 编辑农机服务
farmMachineRegister = '/farmMachine/machineWork/app/register', // 参与服务
} }
/** /**
...@@ -68,3 +69,14 @@ export function farmMachineEdit(params = {}) { ...@@ -68,3 +69,14 @@ export function farmMachineEdit(params = {}) {
params, params,
}) })
} }
/**
* @param params 请求参数
* @description: 参与服务
*/
export function farmMachineRegister(params = {}) {
return otherHttp.post({
url: Api.farmMachineRegister,
params,
})
}
...@@ -39,6 +39,18 @@ ...@@ -39,6 +39,18 @@
} }
}, },
{ {
"path": "pages/nongchang/create-nongchang-form",
"style": {
"navigationBarTitleText": "添加农场",
"backgroundColorTop": "#e6f5e8",
"backgroundColorBottom": "#e6f5e8",
"enablePullDownRefresh": true,
"app-plus": {
"bounce": false
}
}
},
{
"path": "pages/chanxiao/chanxiao", "path": "pages/chanxiao/chanxiao",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "",
......
...@@ -78,84 +78,11 @@ ...@@ -78,84 +78,11 @@
}, },
// 采购需求列表 // 采购需求列表
purchaseDemands: [ purchaseDemands: [],
// {
// id: 1,
// image: '/static/images/codefun/028ebd16358e350cdd341698948bf156.png',
// tag: {
// text: '急需',
// show: true,
// },
// title: '精品有机白菜 50吨',
// deadline: '2025.11.12 前',
// location: '山东合肥',
// price: '1.5-2.0',
// unit: '/斤',
// quoteCount: '12人报价',
// actionText: '立即报价',
// },
// {
// id: 2,
// image: '/static/images/codefun/361ea05e8940b0235c696764775a3f00.png',
// tag: {
// text: '',
// show: false,
// },
// title: '红富士苹果 20吨',
// deadline: '2025.11.12 前',
// location: '山东烟台',
// price: '5.5-6.5',
// unit: '/斤',
// quoteCount: '8人报价',
// actionText: '立即报价',
// icons: {
// deadline: '/static/images/codefun/56353ebdea095baedbcb33fc53f68a03.png',
// location: '/static/images/codefun/c98744e63719b5413f260ec6a899ee20.png',
// quote: '/static/images/codefun/bcf6538c8728a2894c90d4463c4c9520.png',
// },
// },
// {
// id: 3,
// image: '/static/images/codefun/361ea05e8940b0235c696764775a3f00.png',
// tag: {
// text: '',
// show: false,
// },
// title: '胡萝卜 30吨',
// deadline: '2025.11.12 前',
// location: '河北石家庄',
// price: '',
// unit: '',
// quoteCount: '8人报价',
// actionText: '立即报价',
// contactText: '在线咨询',
// icons: {
// deadline: '/static/images/codefun/56353ebdea095baedbcb33fc53f68a03.png',
// location: '/static/images/codefun/c98744e63719b5413f260ec6a899ee20.png',
// quote: '/static/images/codefun/bcf6538c8728a2894c90d4463c4c9520.png',
// },
// },
],
total: 0, total: 0,
// 供应信息列表 // 供应信息列表
supplyInfos: [ supplyInfos: [],
// {
// id: 1,
// image: '/static/images/codefun/b9ce5bff0be96948372f9f688c49fdb3.png',
// tag: {
// text: '推广',
// show: true,
// },
// title: '优质草莓供应商',
// description: '多品种优质草莓常年供应,品质保证',
// location: '广东深圳',
// actionText: '立即报价',
// icons: {
// location: '/static/images/codefun/c98744e63719b5413f260ec6a899ee20.png',
// },
// },
],
}) })
// 获取采购需求列表 // 获取采购需求列表
function getPurchaseList() { function getPurchaseList() {
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
classifyText: '', classifyText: '',
inputTextArea: '', inputTextArea: '',
image: null, image: null,
imageObj: null,
}, },
rules: [ rules: [
{ {
...@@ -138,8 +139,25 @@ ...@@ -138,8 +139,25 @@
pageData.form = res pageData.form = res
pageData.form.address = `${getTextByCode(res.province)}/${getTextByCode(res.city)}/${getTextByCode(res.country)}` pageData.form.address = `${getTextByCode(res.province)}/${getTextByCode(res.city)}/${getTextByCode(res.country)}`
pageData.form.classifyText = pageData.options.classify.find((item) => item.value == res.classify)?.text pageData.form.classifyText = pageData.options.classify.find((item) => item.value == res.classify)?.text
pageData.form.imageObj = pageData.form.image && parseUrlInfo(pageData.form.image)
}) })
} }
function parseUrlInfo(url) {
// 从URL中提取文件名
const pathParts = url.split('/')
const fileName = pathParts[pathParts.length - 1]
// 提取扩展名
const fileParts = fileName.split('.')
const extname = fileParts[fileParts.length - 1]
// 返回格式化的对象
return {
name: fileName,
extname: extname,
url: url,
}
}
function handleChangeTime(e) { function handleChangeTime(e) {
pageData.form.deadLine = e.result pageData.form.deadLine = e.result
...@@ -263,6 +281,7 @@ ...@@ -263,6 +281,7 @@
示例图片 示例图片
</view> </view>
<uni-file-picker <uni-file-picker
:value="form.imageObj"
ref="uploadRef" ref="uploadRef"
limit="1" limit="1"
:auto-upload="false" :auto-upload="false"
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
city: '', city: '',
country: '', country: '',
image: null, image: null,
imageObj: null,
}, },
rules: [ rules: [
{ {
...@@ -161,8 +162,25 @@ ...@@ -161,8 +162,25 @@
pageData.form.address = `${getTextByCode(res.province)}/${getTextByCode(res.city)}/${getTextByCode(res.country)}` pageData.form.address = `${getTextByCode(res.province)}/${getTextByCode(res.city)}/${getTextByCode(res.country)}`
pageData.form.statusText = pageData.options.status.find((item) => item.value == res.status).text pageData.form.statusText = pageData.options.status.find((item) => item.value == res.status).text
pageData.form.classifyText = pageData.options.classify.find((item) => item.value == res.classify).text pageData.form.classifyText = pageData.options.classify.find((item) => item.value == res.classify).text
pageData.form.imageObj = pageData.form.image && parseUrlInfo(pageData.form.image)
}) })
} }
function parseUrlInfo(url) {
// 从URL中提取文件名
const pathParts = url.split('/')
const fileName = pathParts[pathParts.length - 1]
// 提取扩展名
const fileParts = fileName.split('.')
const extname = fileParts[fileParts.length - 1]
// 返回格式化的对象
return {
name: fileName,
extname: extname,
url: url,
}
}
function handleChangeTime1(e) { function handleChangeTime1(e) {
pageData.form.supplyStartDate = e.result pageData.form.supplyStartDate = e.result
...@@ -319,6 +337,7 @@ ...@@ -319,6 +337,7 @@
<view class="bg-white" style="padding: 0.875rem 1rem"> <view class="bg-white" style="padding: 0.875rem 1rem">
<view class="mb-1 flex justify-start"> 示例图片 </view> <view class="mb-1 flex justify-start"> 示例图片 </view>
<uni-file-picker <uni-file-picker
:value="form.imageObj"
ref="uploadRef" ref="uploadRef"
limit="1" limit="1"
:auto-upload="false" :auto-upload="false"
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
starttime: '', starttime: '',
estimatedendtime: '', estimatedendtime: '',
picture: null, picture: null,
pictureObj: null,
}, },
rules: [ rules: [
{ {
...@@ -168,12 +169,30 @@ ...@@ -168,12 +169,30 @@
(item) => item.value == pageData.form.urgentdegree, (item) => item.value == pageData.form.urgentdegree,
)?.text )?.text
pageData.form.typeText = pageData.options.type.find((item) => item.value == pageData.form.type)?.text pageData.form.typeText = pageData.options.type.find((item) => item.value == pageData.form.type)?.text
pageData.form.pictureObj = pageData.form.picture && parseUrlInfo(pageData.form.picture)
}) })
.finally(() => { .finally(() => {
pageData.loading = false pageData.loading = false
}) })
} }
function parseUrlInfo(url) {
// 从URL中提取文件名
const pathParts = url.split('/')
const fileName = pathParts[pathParts.length - 1]
// 提取扩展名
const fileParts = fileName.split('.')
const extname = fileParts[fileParts.length - 1]
// 返回格式化的对象
return {
name: fileName,
extname: extname,
url: url,
}
}
function handleChangeTime1(e) { function handleChangeTime1(e) {
pageData.form.starttime = e.result pageData.form.starttime = e.result
pageData.show.time1 = false pageData.show.time1 = false
...@@ -306,6 +325,7 @@ ...@@ -306,6 +325,7 @@
图片 图片
</view> </view>
<uni-file-picker <uni-file-picker
:value="form.pictureObj"
ref="uploadRef" ref="uploadRef"
limit="1" limit="1"
:auto-upload="false" :auto-upload="false"
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import { calculateCacheSize, cleanCache } from '@/components/CacheImage/index' import { calculateCacheSize, cleanCache } from '@/components/CacheImage/index'
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
import { checkUpgrade } from '@/utils/upgrade' import { checkUpgrade } from '@/utils/upgrade'
import * as NongchangAPI from '@/api/model/nongchang'
// import { Permissions, usePermissions } from '@/components/Permissions' // import { Permissions, usePermissions } from '@/components/Permissions'
// import { useUserPermissions } from '@/utils/auth' // import { useUserPermissions } from '@/utils/auth'
...@@ -76,7 +77,9 @@ ...@@ -76,7 +77,9 @@
// const { isPermission } = useUserPermissions('user_default_zIndex_btn') // const { isPermission } = useUserPermissions('user_default_zIndex_btn')
// 用户应急管理 // 用户应急管理
// const { isPermission: emergencyPermission } = useUserPermissions('emergency_response_btn') // const { isPermission: emergencyPermission } = useUserPermissions('emergency_response_btn')
const pageData = reactive({
farmsListTotal: 0,
})
const items = reactive<Recordable[]>([ const items = reactive<Recordable[]>([
{ {
title: '我的农场', title: '我的农场',
...@@ -84,9 +87,15 @@ ...@@ -84,9 +87,15 @@
disabled: false, disabled: false,
show: true, show: true,
handle: () => { handle: () => {
uni.navigateTo({ if (pageData.farmsListTotal > 0) {
url: '/pages/wode/wode', uni.navigateTo({
}) url: '/pages/wode/wode',
})
} else {
uni.navigateTo({
url: '/pages/nongchang/create-nongchang-form',
})
}
}, },
}, },
{ {
...@@ -167,7 +176,19 @@ ...@@ -167,7 +176,19 @@
}, },
]) ])
function getFarmsList() {
NongchangAPI.farmsList({
pageNo: 1,
pageSize: 10,
}).then((res) => {
console.log(res)
const { total } = res
pageData.farmsListTotal = total
})
}
onShow(() => { onShow(() => {
getFarmsList()
// 计算缓存 // 计算缓存
calculateCache() calculateCache()
}) })
...@@ -224,6 +245,12 @@ ...@@ -224,6 +245,12 @@
background="transparent" background="transparent"
/> />
<text class="ml-3.5 text-30 text-#67c17a font-bold">{{ item.title }}</text> <text class="ml-3.5 text-30 text-#67c17a font-bold">{{ item.title }}</text>
<text v-show="index === 0 && pageData.farmsListTotal === 0" class="text-red"
>({{ pageData.farmsListTotal || 0 }})</text
>
<view v-show="index === 0 && pageData.farmsListTotal === 0" class="text-red flex-1 text-right"
>去添加</view
>
</fui-list-cell> </fui-list-cell>
</fui-list> </fui-list>
<fui-list class="rd-3 overflow-hidden shadow !mt-20rpx" :top-border="false"> <fui-list class="rd-3 overflow-hidden shadow !mt-20rpx" :top-border="false">
......
<script setup lang="ts"> <script setup lang="ts">
import { reactive } from 'vue' import { reactive } from 'vue'
import * as LinghuoyonggongAPI from '@/api/model/linghuoyonggong' import * as NongjifuwuAPI from '@/api/model/nongjifuwu'
import { getCurrentDate } from '@/utils/date'
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
const { getUserInfo } = useUserStore() const { getUserInfo } = useUserStore()
...@@ -8,26 +9,69 @@ ...@@ -8,26 +9,69 @@
show: false, show: false,
content: '', content: '',
form: { form: {
employmentId: '', machineId: '',
serviceType: '',
userId: '', userId: '',
reservedname: null, time: '',
reservedmobile: null, startTime: '',
endTime: '',
scope: '',
address: '',
phone: '',
demand: '',
}, },
rules: [ rules: [
{ {
name: 'reservedname', name: 'startTime',
rule: ['required'], rule: ['required'],
msg: ['请输入预留姓名'], msg: ['请选择开始时间'],
}, },
{ {
name: 'reservedmobile', name: 'endTime',
rule: ['required', 'isMobile'], rule: ['required'],
msg: ['请输入预留手机', '请输入正确的手机号'], msg: ['请选择结束时间'],
},
{
name: 'scope',
rule: ['required'],
msg: ['请填写地区'],
},
{
name: 'address',
rule: ['required'],
msg: ['请填写详细地址'],
},
{
name: 'phone',
rule: ['required'],
msg: ['请填写联系方式'],
},
{
name: 'demand',
rule: ['required'],
msg: ['请填写需求'],
}, },
], ],
}) })
const dict = reactive({
show: {
time: false,
},
})
function handleTimeChange(e) {
pageData.form.startTime = e.startDate.result
pageData.form.endTime = e.endDate.result
pageData.form.time = `${e.startDate.result}${e.endDate.result}`
dict.show.time = false
}
function handleTimeCancel() {
dict.show.time = false
}
function open(params) { function open(params) {
pageData.form.employmentId = params.id pageData.form.machineId = params.id
pageData.form.serviceType = params.serviceType
pageData.form.userId = getUserInfo.id pageData.form.userId = getUserInfo.id
pageData.show = true pageData.show = true
} }
...@@ -36,21 +80,27 @@ ...@@ -36,21 +80,27 @@
} }
function reset() { function reset() {
pageData.form = { pageData.form = {
employmentId: '', machineId: '',
serviceType: '',
userId: '', userId: '',
reservedname: null, time: '',
reservedmobile: null, startTime: '',
endTime: '',
scope: '',
address: '',
phone: '',
demand: '',
} }
} }
const formRef = ref() const formRef = ref()
function submit() { function submit() {
formRef.value.validator(pageData.form, pageData.rules, true).then((res) => { formRef.value.validator(pageData.form, pageData.rules, true).then((res) => {
if (res.isPassed) { if (res.isPassed) {
LinghuoyonggongAPI.employmentRegister(pageData.form).then(() => { NongjifuwuAPI.farmMachineRegister(pageData.form).then(() => {
reset() reset()
close() close()
uni.showToast({ uni.showToast({
title: '报价成功', title: '提交成功',
icon: 'success', icon: 'success',
}) })
}) })
...@@ -70,43 +120,51 @@ ...@@ -70,43 +120,51 @@
</view> </view>
<view class="text-left"> <view class="text-left">
<fui-form ref="formRef"> <fui-form ref="formRef">
<fui-row :gutter="10">
<fui-col :span="12">
<fui-input
marginTop="30"
size="24"
placeholder="请填写预留姓名"
v-model="pageData.form.reservedname"
></fui-input>
</fui-col>
<fui-col :span="12">
<fui-input
marginTop="30"
size="24"
placeholder="请填写预留手机"
v-model="pageData.form.reservedmobile"
></fui-input>
</fui-col>
</fui-row>
<fui-input <fui-input
marginTop="30" marginTop="30"
size="24" size="24"
placeholder="请填写作业地点" placeholder="请填写预留手机"
v-model="pageData.form.reservedmobile" v-model="pageData.form.phone"
></fui-input>
<fui-input
marginTop="30"
size="24"
placeholder="请填写作业地区"
v-model="pageData.form.scope"
></fui-input>
<fui-input
marginTop="30"
size="24"
placeholder="请填写作业详细地址"
v-model="pageData.form.address"
></fui-input> ></fui-input>
<fui-input <fui-input
marginTop="30" marginTop="30"
size="24" size="24"
placeholder="请选择作业时间" placeholder="请选择作业时间"
v-model="pageData.form.reservedmobile" v-model="pageData.form.time"
@click="dict.show.time = true"
></fui-input> ></fui-input>
<fui-textarea :marginTop="30" size="24" placeholder="简要说明作业需求"></fui-textarea> <fui-textarea
v-model="pageData.form.demand"
:marginTop="30"
size="24"
placeholder="简要说明作业需求"
></fui-textarea>
<view style="margin-top: 30rpx"> <view style="margin-top: 30rpx">
<fui-button type="warning" text="确定" bold radius="96rpx" @click="submit"></fui-button> <fui-button type="warning" text="确定" bold radius="96rpx" @click="submit"></fui-button>
</view> </view>
</fui-form> </fui-form>
</view> </view>
</fui-dialog> </fui-dialog>
<fui-date-picker
:show="dict.show.time"
type="3"
range
@change="handleTimeChange"
@cancel="handleTimeCancel"
></fui-date-picker>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
:deep(.fui-dialog__body) { :deep(.fui-dialog__body) {
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
startTime: '', startTime: '',
endTime: '', endTime: '',
picture: '', picture: '',
pictureObj: null,
}, },
rules: [ rules: [
{ {
...@@ -99,11 +100,28 @@ ...@@ -99,11 +100,28 @@
.then((res) => { .then((res) => {
console.log(res) console.log(res)
pageData.form = res pageData.form = res
pageData.form.pictureObj = pageData.form.picture && parseUrlInfo(pageData.form.picture)
}) })
.finally(() => { .finally(() => {
pageData.loading = false pageData.loading = false
}) })
} }
function parseUrlInfo(url) {
// 从URL中提取文件名
const pathParts = url.split('/')
const fileName = pathParts[pathParts.length - 1]
// 提取扩展名
const fileParts = fileName.split('.')
const extname = fileParts[fileParts.length - 1]
// 返回格式化的对象
return {
name: fileName,
extname: extname,
url: url,
}
}
function handleChangeTime1(e) { function handleChangeTime1(e) {
pageData.form.startTime = e.result pageData.form.startTime = e.result
...@@ -198,6 +216,7 @@ ...@@ -198,6 +216,7 @@
<view class="bg-white" style="padding: 0.875rem 0.35rem"> <view class="bg-white" style="padding: 0.875rem 0.35rem">
<view class="mb-1 flex justify-start"> 图片 </view> <view class="mb-1 flex justify-start"> 图片 </view>
<uni-file-picker <uni-file-picker
:value="form.pictureObj"
ref="uploadRef" ref="uploadRef"
limit="1" limit="1"
:auto-upload="false" :auto-upload="false"
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
scope: '', scope: '',
type: '', type: '',
picture: '', picture: '',
pictureObj: null,
}, },
rules: [ rules: [
{ {
...@@ -82,11 +83,30 @@ ...@@ -82,11 +83,30 @@
.then((res) => { .then((res) => {
console.log(res) console.log(res)
pageData.form = res pageData.form = res
pageData.form.pictureObj = pageData.form.picture && parseUrlInfo(pageData.form.picture)
}) })
.finally(() => { .finally(() => {
pageData.loading = false pageData.loading = false
}) })
} }
function parseUrlInfo(url) {
// 从URL中提取文件名
const pathParts = url.split('/')
const fileName = pathParts[pathParts.length - 1]
// 提取扩展名
const fileParts = fileName.split('.')
const extname = fileParts[fileParts.length - 1]
// 返回格式化的对象
return {
name: fileName,
extname: extname,
url: url,
}
}
const toastRef = ref() const toastRef = ref()
const uploadRef = ref() const uploadRef = ref()
// 文件上传 // 文件上传
...@@ -164,6 +184,8 @@ ...@@ -164,6 +184,8 @@
图片 图片
</view> </view>
<uni-file-picker <uni-file-picker
:value="form.pictureObj"
:max-size="1024"
ref="uploadRef" ref="uploadRef"
limit="1" limit="1"
:auto-upload="false" :auto-upload="false"
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { reactive } from 'vue' import { reactive } from 'vue'
import { onPullDownRefresh, onLoad, onShow } from '@dcloudio/uni-app' import { onPullDownRefresh, onLoad, onShow } from '@dcloudio/uni-app'
import * as WodeAPI from '@/api/model/wode' import * as WodeAPI from '@/api/model/wode'
import * as NongchangAPI from '@/api/model/nongchang'
// 下拉刷新 // 下拉刷新
onPullDownRefresh(() => { onPullDownRefresh(() => {
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
onLoad(() => { onLoad(() => {
getBizCommonFileList() getBizCommonFileList()
getFarmsList()
}) })
// 页面数据 // 页面数据
...@@ -73,28 +75,42 @@ ...@@ -73,28 +75,42 @@
commonResources: { commonResources: {
title: '常用资源', title: '常用资源',
actionText: '', actionText: '',
resources: [ icon: {
{ 1: {
id: 1, icon: '/src/static/images/codefun/doc_img.png',
icon: '/static/images/codefun/38f8cccf12ace58fd9cd4612dce944b0.png', name: '文档格式',
title: '水稻种植合同模版',
size: '125kb',
actionText: '下载',
}, },
{ 2: {
id: 2, icon: '/src/static/images/codefun/elx_img.png',
icon: '/static/images/codefun/38f8cccf12ace58fd9cd4612dce944b0.png', name: '表格格式',
title: '玉米种植技术指南',
size: '210kb',
actionText: '下载',
}, },
{ 3: {
id: 3, icon: '/src/static/images/codefun/pdf_img.png',
icon: '/static/images/codefun/38f8cccf12ace58fd9cd4612dce944b0.png', name: 'PDF格式',
title: '肥料使用记录表',
size: '86kb',
actionText: '下载',
}, },
},
resources: [
// {
// id: 1,
// icon: '/static/images/codefun/38f8cccf12ace58fd9cd4612dce944b0.png',
// title: '水稻种植合同模版',
// size: '125kb',
// actionText: '下载',
// },
// {
// id: 2,
// icon: '/static/images/codefun/38f8cccf12ace58fd9cd4612dce944b0.png',
// title: '玉米种植技术指南',
// size: '210kb',
// actionText: '下载',
// },
// {
// id: 3,
// icon: '/static/images/codefun/38f8cccf12ace58fd9cd4612dce944b0.png',
// title: '肥料使用记录表',
// size: '86kb',
// actionText: '下载',
// },
], ],
}, },
...@@ -155,9 +171,25 @@ ...@@ -155,9 +171,25 @@
pageNo: 1, pageNo: 1,
pageSize: 4, pageSize: 4,
}).then((res) => { }).then((res) => {
console.log(res) const { records } = res
// const { records } = res pageData.commonResources.resources = records
// pageData.commonResources.resources = records })
}
function getFarmsList() {
NongchangAPI.farmsList({
pageNo: 1,
pageSize: 10,
}).then((res) => {
const { records, total } = res
pageData.userInfo.farmName = records[0]?.farmName
pageData.userInfo.certification.icon =
records[0]?.certificationStatus === '0'
? ''
: '/static/images/codefun/b6079649e1f0ba231d158cb10bea118f.png'
pageData.userInfo.certification.text = records[0]?.certificationStatus_dictText
pageData.userInfo.farmDescription = records[0]?.description
pageData.statistics[0].value = total
}) })
} }
...@@ -187,8 +219,92 @@ ...@@ -187,8 +219,92 @@
// 资源下载点击事件 // 资源下载点击事件
function onDownloadClick(resource: any) { function onDownloadClick(resource: any) {
console.log('点击下载:', resource) // 阻止事件冒泡
// 在这里添加具体的下载点击逻辑 event?.stopPropagation()
// 显示加载提示
uni.showLoading({
title: '下载中...',
mask: true,
})
// 判断是否为H5平台
/* #ifdef H5 */
downloadFileForWeb(resource)
/* #endif */
/* #ifndef H5 */
downloadFileForNative(resource)
/* #endif */
}
// H5平台下载文件函数
function downloadFileForWeb(resource: any) {
const url = resource.fileSrc
// 创建一个临时的a标签用于下载
const link = document.createElement('a')
link.href = url
link.download = resource.fileName || 'download' // 设置下载文件名
link.style.display = 'none'
// 添加到文档并触发点击
document.body.appendChild(link)
link.click()
// 清理
document.body.removeChild(link)
uni.hideLoading()
Message.toast('开始下载')
}
// 原生平台下载文件函数
function downloadFileForNative(resource: any) {
uni.downloadFile({
url: resource.fileSrc,
success: (res) => {
if (res.statusCode === 200) {
uni.saveFile({
tempFilePath: res.tempFilePath,
success: (saveRes) => {
uni.hideLoading()
Message.toast('下载成功')
// 提示用户文件已保存
uni.showModal({
title: '下载完成',
content: `文件已保存至: ${saveRes.savedFilePath}\n是否立即打开?`,
success: (modalRes) => {
if (modalRes.confirm) {
uni.openDocument({
filePath: saveRes.savedFilePath,
fileType: resource.fileType?.toString() || '',
showMenu: true,
fail: () => {
Message.toast('无法打开文件')
},
})
}
},
})
},
fail: (err) => {
uni.hideLoading()
console.error('保存文件失败:', err)
Message.toast('保存文件失败')
},
})
} else {
uni.hideLoading()
Message.toast('下载失败,状态码: ' + res.statusCode)
}
},
fail: (err) => {
uni.hideLoading()
console.error('下载失败:', err)
Message.toast('网络错误,下载失败')
},
})
} }
// 查看所有资源 // 查看所有资源
...@@ -236,12 +352,15 @@ ...@@ -236,12 +352,15 @@
class="codefun-flex-row codefun-items-center codefun-shrink-0 section_2 codefun-ml-6" class="codefun-flex-row codefun-items-center codefun-shrink-0 section_2 codefun-ml-6"
> >
<image <image
class="codefun-shrink-0 image_7" v-show="pageData.userInfo.certification.icon"
class="codefun-shrink-0 image_7 mr-1"
:src="pageData.userInfo.certification.icon" :src="pageData.userInfo.certification.icon"
/> />
<text class="font_3 text_3 codefun-ml-4">{{ <text
pageData.userInfo.certification.text class="font_3 text_3"
}}</text> :style="{ color: pageData.userInfo.certification.icon ? '' : '#fbc428' }"
>{{ pageData.userInfo.certification.text }}</text
>
</view> </view>
</view> </view>
<text class="codefun-self-start font_1 codefun-mt-10">{{ <text class="codefun-self-start font_1 codefun-mt-10">{{
...@@ -347,7 +466,7 @@ ...@@ -347,7 +466,7 @@
@click="onResourceClick(resource)" @click="onResourceClick(resource)"
> >
<view class="codefun-flex-row"> <view class="codefun-flex-row">
<image class="image_15" :src="resource.icon" /> <image class="image_15" :src="pageData.commonResources.icon[resource.fileType]?.icon" />
<view class="codefun-flex-col codefun-items-start group_14 codefun-ml-12"> <view class="codefun-flex-col codefun-items-start group_14 codefun-ml-12">
<text class="font_9">{{ resource.fileName }}</text> <text class="font_9">{{ resource.fileName }}</text>
<text class="font_6 codefun-mt-12">{{ resource.fileSize }}</text> <text class="font_6 codefun-mt-12">{{ resource.fileSize }}</text>
......
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { store } from '/@/store' import { store } from '/@/store'
import { Storage } from '@/utils/storage'
import * as UserInfoAPI from '@/api/model/userInfo' import * as UserInfoAPI from '@/api/model/userInfo'
interface dictItem { interface dictItem {
...@@ -22,23 +23,35 @@ export const useDictStore = defineStore({ ...@@ -22,23 +23,35 @@ export const useDictStore = defineStore({
getters: { getters: {
getDictList(): DictListVO { getDictList(): DictListVO {
if (Object.keys(this.dictList).length === 0) { if (Object.keys(this.dictList).length === 0) {
UserInfoAPI.dictList().then((res) => { this.dictList = JSON.parse(Storage.get('dictList'))
this.dictList = res
})
return this.dictList
} }
return this.dictList return this.dictList
}, },
// 获取指定类型的字典项(同步方法,需要先确保数据已加载)
getDictByType:
(state) =>
(type: string): dictItem[] => {
return state.dictList[type] || []
},
}, },
actions: { actions: {
setDictList(dictList: DictListVO): void { async setDictList() {
this.dictList = dictList if (Object.keys(this.dictList).length === 0) {
try {
const res = await UserInfoAPI.dictList()
this.dictList = res as DictListVO
Storage.set('dictList', JSON.stringify(this.dictList))
} catch (error) {
console.log('获取字典列表失败', error)
}
}
}, },
/** /**
* 清空字典数据 * 清空字典数据
*/ */
clearDict(): void { clearDict(): void {
this.dictList = {} this.dictList = {}
Storage.remove('dictList')
}, },
}, },
}) })
......
/**
* 获取当前日期,格式为 yyyy-MM-dd
* @returns 当前日期字符串,格式为 yyyy-MM-dd
*/
export function getCurrentDate(): string {
const now = new Date()
const year = now.getFullYear()
// 获取月份,注意getMonth返回0-11,需要+1
const month = String(now.getMonth() + 1).padStart(2, '0')
// 获取日期,确保两位数格式
const day = String(now.getDate()).padStart(2, '0')
// 返回格式化后的日期字符串
return `${year}-${month}-${day}`
}
/**
* 格式化日期为yyyy-MM-dd格式
* @param date 日期对象、时间戳或日期字符串
* @returns 格式化后的日期字符串
*/
export function formatDate(date: Date | number | string): string {
const d = new Date(date)
const year = d.getFullYear()
const month = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论