代码更新

This commit is contained in:
GaoHao
2025-02-26 19:46:20 +08:00
parent 7519ffced3
commit b4a0393d2d
413 changed files with 7483 additions and 60762 deletions

View File

@@ -1,8 +0,0 @@
<template>
</template>
<script>
</script>
<style>
</style>

View File

@@ -6,10 +6,10 @@
label-position="top" label-width="350">
<view class="block">
<view class="input-padding-b-0 ">
<uni-forms-item label="分名称" required name="name">
<uni-forms-item label="分名称" required name="name">
<view class="u-m-t-16 u-m-b-24">
<uni-easyinput paddingNone :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="category.name" placeholder="输入分名称" />
:inputBorder="inputBorder" v-model="category.name" placeholder="输入分名称" />
</view>
</uni-forms-item>
</view>
@@ -24,7 +24,7 @@
<view class="u-flex u-row-between u-col-center">
<view class="label-title">分组状态</view>
<view class="u-flex">
<my-switch v-model="category.isShow"></my-switch>
<my-switch v-model="category.status"></my-switch>
</view>
</view>
</uni-forms-item>
@@ -100,6 +100,8 @@
tbProductGroupPost
} from '@/http/yskApi/shop.js'
import { addProdGroup, updateProdGroup } from '@/api/product.js'
const $productCategory = {
add: tbProductGroupPost,
del: tbProductGroupDelete,
@@ -107,26 +109,27 @@
get: tbProductGroupGet
}
const refAddChilCate = ref(null)
const refAddChilCateTitle = ref('添加子分类')
function refAddChilCateClose() {
refAddChilCate.value.close()
categoryChild.value = {
...categoryBasicData
}
const option = reactive({
type: ''
})
// 构造分类的基础数据
const categoryBasicData = {
id: '',
name: '',
status: 1,
sort: 0,
useTime: 0,
saleEndTime:'',
saleStartTime:'',
}
let refMoreSheet = ref(null)
let selItem = {
data: '',
index: ''
}
// 分类列表
const category = reactive({
...categoryBasicData,
childrenList: []
})
// 表单样式
const placeholderStyle = ref('font-size:28rpx;')
//表单边框
@@ -148,242 +151,49 @@
}]
}
}
const refFiles = ref([])
function setRefFile(index) {
refFiles.value[index] = null;
return (el) => {
if (el) {
refFiles.value[index] = el;
}
};
}
const time=reactive({
show:false,
val:'',
key:''
})
function timeCancel(){
time.show=false
}
function timeConfirm(e){
console.log(e);
if(time.key=='start'){
category.saleStartTime=e.value
}else{
category.saleEndTime=e.value
}
time.val=''
time.show=false
}
function changeTime(key) {
time.key=key;
time.show=true;
}
function toTimer(timer, index) {
console.log(timer);
uni.setStorageSync('timer', timer.map(v => {
return {
...v,
cycleChecked: v.cycleChecked.map(v => v.value)
}
}))
go.to('PAGES_CATEGORY_TIMER', {
index: index
})
}
function returnTimers(timers) {
const {
listingTime,
offShelf,
cycleChecked
} = timers
let len = cycleChecked.length
if (len === 7) {
return `每天 ${listingTime.value} - ${offShelf.value}`
}
let result = cycleChecked.reduce((prve, cur) => {
return prve + cur.text.replace('星期', '周')
}, '')
return `${result} ${listingTime.value} - ${offShelf.value}`
}
//图片上传
function FileUploadprogress() {
}
function FileUploadsuccess() {
}
function FileUploadail() {
}
function FileUploadselect(e) {
// TEST
// FormData.images.push(e)
}
function returnOptionsBasicData() {
return {
...categoryOptionsBasicData
}
}
// 构造分类的基础数据
const categoryBasicData = {
id: '',
name: '',
isShow: 1,
sort: 0,
productIds: [],
saleTime: [],
useTime: 0,
saleEndTime:'',
saleStartTime:'',
shopId: uni.getStorageSync('shopId')
}
const categoryChild = ref({
...categoryBasicData
})
function onFieldChange(e) {
console.log(e);
}
// 分类列表
const category = reactive({
...categoryBasicData,
childrenList: []
})
//添加子分类
function addcategoryChildren() {
refAddChilCate.value.open()
// category.childrenList.push({
// ...categoryBasicData
// })
// scrollPageBottom()
}
//页面滚动到最底部
function scrollPageBottom() {
nextTick(() => {
uni.pageScrollTo({
duration: 100, // 过渡时间
scrollTop: 100000, // 滚动的实际距离
})
})
}
//设置表单验证规则
function setFormRules() {
form.value.setRules(rules)
}
const formRefs = ref([]);
//绑定表单元素
function setFormRef(index) {
formRefs.value[index] = null;
return (el) => {
if (el) {
formRefs.value[index] = el;
}
};
}
// 绑定option input元素
const refFormInput = ref([])
function setFormInputRef(index, index1) {
const newIndex = index * 10000 + index1
return (el) => {
if (el) {
if (!refFormInput.value[newIndex]) {
refFormInput.value[newIndex] = el;
}
}
}
}
// 当表单内容输入变化根据配置的rules进行验证
function inpuChange(index, index1) {
const newIndex = index * 10000 + index1
console.log(refFormInput.value[newIndex]);
refFormInput.value[newIndex].onFieldChange()
}
function triggerEvent(emitName, data) {
if (emitName) {
uni.$emit(emitName, data)
}
}
const option = reactive({
type: ''
})
function isNoEmpty(obj) {
return obj && JSON.stringify(obj) !== '{}'
}
/**
* 监听定时器保存,拿到数据
* @param {Boolean} open //控制开启或关闭监听
*/
function watchTimerSave(open = true) {
if (open) {
uni.$on('timerSave', function(res) {
const {
index,
data
} = res
console.log('timerSave get');
console.log(res);
if (index == -1) {
category.timers = data
} else {
category.childrenList[index].timers = data
}
})
} else {
uni.$off('timerSave', function(data) {
console.log('timerSave remove');
})
}
}
watchTimerSave()
onLoad(params => {
let cateItem = uni.getStorageSync('cateItem')
if (isNoEmpty(params)) {
option.type = params.type
}
if (option.type === 'edit' && isNoEmpty(cateItem)) {
console.log(cateItem);
for (let i in cateItem) {
if (i.substring(0, 2) === 'is' && i.length > 2) {
cateItem[i] = cateItem[i] * 1
} else {
cateItem[i] = cateItem[i] === 'null' ? '' : cateItem[i]
}
}
Object.assign(category, cateItem)
}
console.log(category);
onLoad(option => {
uni.setNavigationBarTitle({
title: option.type === 'add' ? '添加分组' : '编辑分组'
})
})
function emitcategorySave() {
// emitcategorySave 触发规格保存事件将数据给到添加商品页面
// guigeEdit 触发规格保存事件将数据给到添加规格页面
uni.removeStorageSync('guige')
triggerEvent(emitName, category.list)
/**
* 打开时间弹窗
* @param {Object} key
*/
function changeTime(key) {
time.key=key;
time.show=true;
}
/**
* 关闭时间弹窗
*/
function timeCancel(){
time.show=false
}
/**
* 时间设置确定
* @param {Object} e
*/
function timeConfirm(e){
console.log(e);
if(time.key=='start'){
category.saleStartTime=e.value+':00'
}else{
category.saleEndTime=e.value+':00'
}
time.val=''
time.show=false
}
@@ -421,31 +231,22 @@
}
let timer = null
function onfileChange(val, data, key) {
data[key] = val
}
async function save() {
let isAllPassForm = 0
const formRules = {}
const result = []
result.push(...returnValidateResult(category))
for (let obj of category.childrenList) {
const res = returnValidateResult(obj)
result.push(...res)
}
if (result.length) {
return infoBox.showToast(result[0].errMeessage)
}
if (option.type === 'edit') {
const res = await $productCategory.update({
const res = await updateProdGroup({
...category,
childrenList: ''
})
} else {
const res = await $productCategory.add({
const res = await addProdGroup({
...category,
childrenList: ''
})
@@ -456,9 +257,7 @@
clearTimeout(timer)
go.back()
}, 1500);
// const res = await form.value.validate().then(res => {
// go.back()
// })
}
</script>

View File

@@ -1,213 +0,0 @@
<template>
<view class="u-p-30 min-page">
<view class="u-flex">
<view style="width: 210rpx;">
<my-button shape="circle" @click="addTimer">添加定时器</my-button>
</view>
</view>
<view class="list u-m-t-20" v-if="list.length">
<view class="block" v-for="(item,index) in list" :key="index">
<view class="u-flex u-row-between">
<view>定时器{{index+1}}</view>
<uni-icons @click="delTimer(index)" type="trash"></uni-icons>
</view>
<view class="u-flex u-m-t-20 u-row-between">
<view>周期</view>
<view @click="selectAllClick(index)">全选</view>
</view>
<view class="u-m-t-20">
<uni-data-checkbox multiple v-model="item.cycleChecked" :localdata="cycle"></uni-data-checkbox>
</view>
<view class="u-m-t-20">
<view class="u-flex">
<view>上架时间:</view>
<view class="u-flex-1 u-m-l-10">
<picker mode="multiSelector" @change="listingTimeChange($event,index)"
:value="item.listingTime.index" :range="times">
<view class="bg-gray u-p-l-20 u-p-t-6 u-p-b-6 u-p-r-20 ">
{{item.listingTime.value}}
</view>
</picker>
</view>
</view>
<view class="u-flex u-m-t-20">
<view>下架时间:</view>
<view class="u-flex-1 u-m-l-10">
<picker mode="multiSelector" @change="offShelfChange($event,index)"
:value="item.offShelf.index" :range="times">
<view class="bg-gray u-p-l-20 u-p-t-6 u-p-b-6 u-p-r-20 ">
{{item.offShelf.value}}
</view>
</picker>
</view>
</view>
</view>
</view>
</view>
<view class="u-flex u-row-center u-m-t-60">
<my-button width="580" shape="circle" @click="save">保存</my-button>
</view>
</view>
</template>
<script setup>
import {
onLoad,
onReady
} from '@dcloudio/uni-app';
import {
ref
} from 'vue';
import go from '@/commons/utils/go.js';
import myButton from '@/components/my-components/my-button.vue'
//返回一天的时间 时分格式
function returnDayTime() {
return new Array(2).fill(1).map((v, index) => {
if (index === 0) {
return new Array(24).fill(1).map((hour, index) => {
return `0${index}`.slice(-2)
})
}
if (index === 1) {
return new Array(60).fill(1).map((hour, index) => {
return `0${index}`.slice(-2)
})
}
})
}
const times = ref(returnDayTime())
let defaultTimeIndex = ref(0)
function getTime(indexArr) {
const hour = times.value[0][indexArr[0]]
const month = times.value[1][indexArr[1]]
return `${hour}:${month}`
}
//获取$event.detail.value
function getEnentDetailValue(e) {
return e.detail.value
}
function setListTimeValue(index, key, time) {
list.value[index][key].value = time
}
function listingTimeChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'listingTime', time)
}
function offShelfChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'offShelf', time)
}
const cycle = [{
value: 0,
text: '星期一'
},
{
value: 1,
text: '星期二'
},
{
value: 2,
text: '星期三'
},
{
value: 3,
text: '星期四'
},
{
value: 4,
text: '星期五'
},
{
value: 5,
text: '星期六'
},
{
value: 6,
text: '星期日'
}
]
const ListDataconstructor = {
cycleChecked: [0, 1, 2, 3, 4, 5, 6],
}
function returnBasicTimeConstructor() {
return {
listingTime: {
value: '09:00',
index: [9, 0]
},
offShelf: {
value: '18:00',
index: [18, 0]
}
}
}
const list = ref([returnBasicDataConstructor()])
function returnBasicDataConstructor() {
return {
...ListDataconstructor,
...returnBasicTimeConstructor()
}
}
function addTimer() {
list.value.push(returnBasicDataConstructor())
}
function delTimer(index) {
list.value.splice(index,1)
}
function selectAllClick(index){
list.value[index].cycleChecked=ListDataconstructor.cycleChecked
}
let index=null
// 触发定时器保存事件将数据给到添加商品页面
function emitTimerSave(){
uni.$emit('timerSave',{
data:list.value.map(v=>{
return {
...v,
cycleChecked:v.cycleChecked.map(index=>{
return {value:index,text:cycle[index].text}
})
}
}),
index:index
})
go.back()
}
function save(){
console.log(list.value);
emitTimerSave()
}
onLoad((opt)=>{
index=opt.index
const arr=uni.getStorageSync('timer')
if(arr.length){
list.value=arr
}
})
</script>
<style lang="scss">
.min-page {
background-color: #F9F9F9;
}
.block {
background: #FFFFFF;
border-radius: 18rpx 18rpx 18rpx 18rpx;
padding: 30rpx;
margin-bottom: 20rpx;
}
</style>