Skip to content

整理的代码片段

前端一键可控制横纵页面

html

<style>
    .flex-table-container {
        display:         flex;
        justify-content: center; /* 水平居中 */
        padding-top:     10px;
    }

    .flex-table {
        display:        flex;
        flex-direction: column;
        width:          70%; /* 新增: 设置宽度为80% */
    }

    .flex-row {
        display: flex;
        width:   100%;
    }

    .flex-cell {
        flex:         1;
        padding:      4px;
        box-sizing:   border-box;
        border:       1px solid #000;
        border-width: 0 1px 1px 0; /* 只设置左右下边框 */
        line-height:  16px; /* 新增行高设置 */
    }

    /* 设置第一列和最后一列的边框 */
    .flex-row > :first-child {
        border-left-width: 1px;
    }

    .flex-row > :last-child {
        border-right-width: 1px;
    }

    /* 设置第一行和最后一行的边框 */
    .flex-row:first-child > .flex-cell {
        border-top-width: 1px;
    }

    .flex-row:last-child > .flex-cell {
        border-bottom-width: 1px;
    }

    /* 避免角落处边框叠加 */
    .flex-row:first-child > .flex-cell:first-child {
        border-top-left-radius: 4px;
    }

    .flex-row:first-child > .flex-cell:last-child {
        border-top-right-radius: 4px;
    }

    .flex-row:last-child > .flex-cell:first-child {
        border-bottom-left-radius: 4px;
    }

    .flex-row:last-child > .flex-cell:last-child {
        border-bottom-right-radius: 4px;
    }

    .header-row {
        /* 可选:为表头行添加特定样式,如更明显的下边框 */
        background-color: #edf3fe; /* 示例背景颜色 */
        font-weight:      bold; /* 字体加粗 */
    }

    .forminput {
        width: 99.9%;
    }

    .flex-item {
        flex: 0 0 auto; /* 关闭增长和收缩,使用指定的宽度 */
    }

    .flex-item1 {
        flex-basis: 10%;
    }

    .flex-item2 {
        flex-basis: 20%;
    }

    .flex-item3 {
        flex-basis: 30%;
    }

    .flex-item4 {
        flex-basis: 40%;
    }

    .flex-item5 {
        flex-basis: 50%;
    }

    .flex-item6 {
        flex-basis: 60%;
    }

    .flex-item7 {
        flex-basis: 70%;
    }

    .flex-item8 {
        flex-basis: 80%;
    }

    .flex-item9 {
        flex-basis: 90%;
    }

    .flex-item10 {
        flex-basis: 100%;
    }

    input[type="radio"] {
        margin-left: 15px;
    }

    .btn-submit {
        text-align: center;
    }

    .section-block {
        font-weight: bolder;
    }

    .text-red {
        color: red;
    }

    .my-select {
        width: 70%;
    }

    .flex-between {
        display:         flex;
        justify-content: space-between;
    }

    .flex-column {
        display:        flex;
        flex-direction: column; /* 垂直排列子元素 */
    }
    .flex-part1 {
        flex: 1;
    }
    .flex-part2 {
        flex: 2;
    }
    .flex-part3 {
        flex: 3;
    }
    .flex-part4 {
        flex: 4;
    }
    .flex-part5 {
        flex: 5;
    }
    .flex-part6 {
        flex: 6;
    }
    .flex-part7 {
        flex: 7;
    }
    .flex-part8 {
        flex: 8;
    }
    .flex-part9 {
        flex: 9;
    }
    .flex-wrap {
        display:   flex;
        flex-wrap: wrap;
    }

    .flex-line {
        display:        flex;
        flex-direction: row;
    }
    .left-side {
        justify-content: flex-start; /* 左侧子元素靠左对齐 */
        padding-left:    10px;
    }
    .right-side {
        padding-right:   10px;
        justify-content: flex-end; /* 右侧子元素靠右对齐 */
    }
    .add-btn, .del-btn {
        display:     inline-block;
        width:       24px;
        font-size:   36px;
        color:       blue;
        width:       100%;
        height:      100%;
        line-height: 36px;
        text-align:  center;
    }
    .del-btn {
        color: red;
    }
    .text-bold {
        font-weight: bolder;
    }
    .text-center {
        text-align: center;
    }
</style>
<form method='post'
      target='hiddenwin'
      id="layout-form"
      enctype="multipart/form-data">
    <div class="flex-table-container">
        <div class="flex-table">
            <div class="flex-row header-row">
                <div class="flex-cell"><?php echo $title; ?></div>
            </div>
        </div>
    </div>
    <div class="flex-table-container">
        <div class="flex-table">
            <div class="flex-row btn-submit">
                <div class='flex-cell'>
                    &nbsp;&nbsp;&nbsp;<?php echo html::submitButton() . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . html::resetButton(); ?>
                </div>
            </div>
        </div>
    </div>
</form>

日志统一封装

php
if ($changes) {
      if(!$id){
          $id = $changes['openby'];
      }
      $this->loadModel('action')->recordLogs($id, 'applyprocess', $changes);
      echo js::alert('success');
}

日志公共方法

php
    /**
     * 记录日志
     *
     * @param $id       记录的id
     * @param $sign     标识
     * @param $changes  日志数据
     * @author shengland
     * @Date   2024/5/28---15:18
     */
    public function recordLogs($id, $sign, $changes) {
        if ($changes) {
            foreach ($changes as $k => $v) {
                if ($v) {
                    if (is_array($v)) { //修改
                        $actionID = $this->loadModel('action')->create($sign, $id, $k);
                        $this->loadModel('action')->logHistory($actionID, $v);
                    }
                    else {  //其他
                        if ($v !== true) {
                            $this->loadModel('action')->create($sign, $id, $k . '_' . $v);
                        }
                        else {
                            $this->loadModel('action')->create($sign, $id, $k);
                        }
                    }
                }
            }
        }
    }

日志记录

php
$changesedit = common::createChanges($olddata, $form_data);
if ($changesedit) {
    $changes['edit'] = $changesedit;
    $this->dao->update('zt_truth')->data($form_data)
        ->autoCheck()
        ->where('id')->eq($id)
        ->exec();
}

获取日志信息

php
$this->assign('actions', $this->action->getList('xxx', $id));

uniapp 监听循环判断

js
  /**
 * 监听catetory
 * @param newVal
 * @param oldVal
 */
'flwData.category'
:

function (newVal, oldVal) {
	let flwData = this.flwData
	let formConfig = this.formConfig
	let that = this
	if(newVal == '2' || newVal == '5') {

		this.$global._.forEach(formConfig, function (v, k) {
			if(v.name == 'reasonForOverBudget') {
				v.isShow = true
				v.editable = true

			}
			if(flwData[v.name]) {
				v.value = flwData[v.name]
			}
			that.$set(formConfig, k, v)
		})
	}
	else {
		this.$global._.forEach(formConfig, function (v, k) {
			if(v.name == 'reasonForOverBudget') {
				v.isShow = false
				v.editable = false
				v.disabled = true

			}
			else if(flwData[v.name]) {
				v.value = flwData[v.name]
			}

			that.$set(formConfig, k, v)
		})
	}
}

,

自定义css 弹性分布

css
    .btn-line-item {
    display: flex;
}

.ade {
    flex: 0.4 1 0;
}

.total-point {
    flex: 0.6 1 0;
}

条件查询

php
       $data = $this->dao->select('*')
                ->from('zt_user')
                ->beginIF($where)->Where($where)->fi()
                ->orderByMy($sort)
                ->fetchAll();

设置超时时间

php
        @ini_set('max_execution_time', 0); // 取消脚本的最大执行时间限制

列表页查询,搜索展示

php
public function list($param = 0, $type = 'all', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) {
        /* Set the pager. */
        $this->app->loadClass('pager', $static = true);
        $pager = pager::init($recTotal, $recPerPage, $pageID);

        if ($type != 'bysearch') {
            $where = '1 = 1';              // all
        }
        else {
            $queryID = (int)$param;
            if ($queryID) {
                $query = $this->search->getQuery($queryID);

                if ($query) {
                    $this->session->set('listQuery', $query->sql);
                    $this->session->set('listForm', $query->form);
                }
                else {
                    $this->session->set('listQuery', "1 = 1");
                }
            }

            $where = $this->session->listQuery;
        }
        
        $list = $this->test->getList($where, $orderBy, $pager);
             
        $this->config->test->list->search['params']['createby']['values'] = $users;
        $this->config->test->list->search['actionURL'] = $this->createLink('test', 'list', "param=myQueryID&type=bysearch");   // search
        $this->config->test->list->search['queryID'] = $param;
        $this->assign('searchForm',$this->fetch('search', 'buildForm', $this->config->test->list->search));     
             
                
        $this->assign('pager', $pager);
        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('param', $param);
}


public function getNewtechlist($search = '', $orderby = 'id_desc', $pager){
    $list = $this->dao->select('*')->from('zt_test')
        ->beginIF($search)
        ->where($search)
        ->Fi()
        ->orderBy($orderby)
        ->page($pager)
        ->fetchAll();

    return $list;
}

单文件上传下载

php
    $file_upload_ids = $this->loadModel('file')->setOtherSavePath('device/upload')->saveUploadOne($type, 'device', $id, $type);
    if ($file_upload_ids) {
        $form_data->{$type_name}[$version]['fileid'] = key($file_upload_ids);
        $form_data->{$type_name}[$version]['filepath'] = current($file_upload_ids);
    }
    /**
     * 保存单个文件
     *
     * @param string $objectType
     * @param string $objectID
     * @param string $extra
     * @access public
     * @return array
     */
    public function saveUploadOne($file_name,$objectType = '', $objectID = '', $extra = '') {
        $fileTitles = array();
        $now = helper::today();
        $files = $this->getUpload($file_name);

        foreach ($files as $id => $file) {
			//上传限制
			$this->setfilesize(filesize($file['tmpname']));
            //end
            move_uploaded_file($file['tmpname'], $this->savePath . $file['pathname']);
            $file['objectType'] = $objectType;
            $file['objectID'] = $objectID;
            $file['addedBy'] = $this->app->user->account;
            $file['addedDate'] = $now;
            $file['extra'] = $extra;
            unset($file['tmpname']);
            $this->dao->insert(TABLE_FILE)->data($file)->exec();
            $fileTitles[$this->dao->lastInsertId()] = $file['title'];
        }
        return $fileTitles;
    }
    /**
     * 下载文件 单个文件
     * @param $file_id 文件id
     * @author shengland
     * @Date   2022/6/6---13:54
     */
    public function downFileOne($fileID,$upload = false) {
        $file = $this->file->getById($fileID);
//        echo json_encode($file);die;
        $file_module = $file->objectType;

        $file->realPath = "../../module/{$file_module}/upload/1/".$file->pathname;
        /* Judge the mode, down or open. */
        $mode = 'down';
        $fileTypes = 'txt|jpg|jpeg|gif|png|bmp|xml|html';
        if (stripos($fileTypes, $file->extension) !== false and $mouse == 'left') $mode = 'open';

        /* If the mode is open, locate directly. */
        if ($mode == 'open') {
            if (file_exists($file->realPath)) $this->locate($file->webPath);
            $this->app->error("The file you visit $fileID not found.", __FILE__, __LINE__, true);
        }
        else {
            /* Down the file. */
            if (file_exists($file->realPath)) {
                $fileName = $file->title . '.' . $file->extension;
                $fileData = file_get_contents($file->realPath);
                $this->sendDownHeader($fileName, $file->extension, $fileData);
            }
            else {
                echo $file->realPath;die;
                $this->app->error("The file you visit $fileID not found.", __FILE__, __LINE__, true);
            }
        }
    }

php model 查询

php
        $ids = $this->dao->select('*')->from('zt_test')
            ->where('id')->gt(0)
            ->BeginIF(!empty($project_ids))
            ->andWhere('projectid')->in($project_ids)
            ->fi()
            ->andWhere('( de')->gt(0)
            ->orWhere('ae')->gt(0)
            ->orWhere('te')->gt(0)
            ->orWhere('pe')->gt(0)
            ->orWhere('pm')->gt(0)
            ->markRight(true)
            ->fetchPairs('projectid', 'projectid');

uniapp 设置缓存与清空缓存

js
uni.clearStorage();
uni.getStorageSync('token');