onclick事件中加href

本文介绍了一种通过点击事件实现页面跳转的方法,使用JavaScript控制窗口定位到指定URL:Add.aspx。此技术常见于网页应用中,以实现用户交互和导航。

onclick="javascript:window.location.href=Add.aspx';“

转载于:https://www.cnblogs.com/dkongyying/archive/2010/12/14/1905294.html

import React, { useState, useEffect } from 'react'; import { ProCard, PageContainer } from '@ant-design/pro-components'; import {Form, Radio, Tree, Row, Col, message, List, Card, Tag, Typography, Space} from 'antd'; import {request} from "@@/plugin-request/request"; import CustomPagination from "./CustomPagination"; const { Title, Text, Paragraph } = Typography; interface SearchResultListProps { keyword?: string; } interface AssetsItem { id: string; dsName: string; dsTableName: string; dsType: string; areaId: string; areaName: string; sysId: string; sysName: string; bussinessObjName: string; bussinessObjId: string; processPointName: string; dsOwnerName: string; dsOwnerNum: string; isConfirm: string; // 后端返回的是字符串 "true"/"false" dsMemo: string; dsRange: string; tags: string; demoData: string; createUser: string; createTime: number; // 时间戳 updateUser: string; updateTime: number; // 时间戳 deleted: number; // 删除标志,0表示未删除 demoFileName: string; demoFilePath: string; demoOssFilePath: string; } // 树形结构组件 const SearchResultList: React.FC<SearchResultListProps> = ({keyword}) => { const [treeData, setTreeData] = useState<any[]>([]); const [assetsData, setAssetsData] = useState<AssetsItem[]>([]); const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // ✅ 新增两个筛选状态 const [isEmpty, setIsEmpty] = useState<boolean>(false); const [dsType, setDsType] = useState<string>(''); const [isConfirm, setIsConfirm] = useState<string>(''); //数据资产分页 const [pageNum, setPageNum] = useState<number>(1); const [totalItems, setTotalItems] = useState<number>(5); // 从接口获取 // 组件加载时自动请求一次树数据 useEffect(() => { const loadInitialData = async () => { // 更新 requestAssetsParam // 请求树结构 const treeData = await fetchTreeData({ keyWord: keyword ?? '', dsType: dsType, isConfirm: isConfirm }); if(treeData){ setTreeData(treeData); }else{ message.error("查询数据为空") } // 请求数据资产 const assetsData = await fetchAssetsData({ keyWord: keyword, dsType: dsType, isConfirm: isConfirm, pageNum:pageNum, pageSize:10 }); if(assetsData){ setAssetsData(assetsData); } }; loadInitialData(); }, [keyword, dsType, isConfirm ,pageNum]); // 当筛选条件变化时重新请求 // 树形数据处理函数,遍历节点 将节点的名称进行拼接 // @ts-ignore const filterTreeData = (nodes) => nodes.map((node: { count: number | null; title: string; children: any; }) => { // @ts-ignore if (node.count <= 0 || node.count == null) { node.title = node.title.replace(/[\s\(\(]*$$(\d+)$$[\s\)\)]*/g, '').trim(); } return { ...node, children: node.children ? filterTreeData(node.children) : [], }; }); // 获取树形结构数据的函数 const fetchTreeData = async (param: { keyWord: string; dsType: string; isConfirm: string; }) => { const res = await request('/ds/dsbaseinfo/searchAssetsTree', { method: 'POST', data:param }); if(res && res.length>0){ return filterTreeData(res || []); } return [] }; // 获取资产详情的函数, const fetchAssetsData = async (param: { keyWord: any; dsType: string; isConfirm: string; pageNum: number; pageSize: number; areaName?: any; }) => { try { const res = await request('/ds/dsbaseinfo/globalSearchAssets', { method: 'POST', data: param, }); if (res && res.list) { setIsEmpty(res.list.length === 0); setTotalItems(res.list.length) return res.list as AssetsItem[]; } else { setIsEmpty(true); return []; } } catch (err) { setIsEmpty(true); message.error('请求失败'); return []; } } //翻页函数 const handlePageChange = (page: number) => { setPageNum(page); }; // 高亮关键词函数 const highlightKeyword = (text: string, keyword: string | null | undefined): React.ReactNode => { if (!keyword || !text || typeof text !== 'string') return text; const regex = new RegExp(`(${keyword})`, 'gi'); // 忽略大小匹配 const parts = text.split(regex); return parts.map((part, index) => part.toLowerCase() === keyword.toLowerCase() ? ( <span key={index} style={{color: 'red', fontWeight: 'bold'}}> {part} </span> ) : ( part ) ); }; // 预览文件函数 const handlePreview = (url: string) => { if (url) { const base64Url = btoa(unescape(encodeURIComponent(url))); window.open('http://10.255.96.51:8012/onlinePreview?url=' + encodeURIComponent(base64Url)); } else { message.error('无法预览文件'); } }; // 点击树节点时触发 const onSelect = async (selectedKeys: string[], info: any) => { const selectedNode = info.node; // ✅ 判断是否是叶子节点或倒数第二层节点 const isLeafNode = selectedNode.isLeaf || !selectedNode.children?.length; const isPenultimateNode = selectedNode.children?.length > 0 && selectedNode.children.every((child: any) => child.isLeaf || !child.children?.length); let param = { keyWord:keyword, pageNum:pageNum, pageSize:10, dsType:dsType, isConfirm:isConfirm, areaName: selectedNode.key.split('_')[0], } if (isLeafNode){ param = { ...param, // @ts-ignore dsName:selectedNode.title } } if (isPenultimateNode) { if(selectedNode.key.includes("系统")){ // @ts-ignore param = {...param,sysName:selectedNode.key.split('_')[2]} } if (selectedNode.key.includes("对象")){ // @ts-ignore param = {...param,bussinessObjName:selectedNode.key.split('_')[2]} } if (selectedNode.key.includes("流程")){ // @ts-ignore param = {...param,processPointName:selectedNode.key.split('_')[2]} } } const assetsData = await fetchAssetsData(param); setAssetsData(assetsData); } // 控制树节点展开 const onExpand = (keys: React.Key[]) => { setExpandedKeys(keys as string[]); }; // ✅ 处理筛选项变化 const handleDsTypeChange = (e: any) => { setDsType(e.target.value) }; const handleIsConfirmChange = (e: any) => { if(e.target.value == '是'){ setIsConfirm('true') }else if (e.target.value == '否'){ setIsConfirm('false') }else{ setIsConfirm('') } }; return ( <PageContainer style={{marginTop: 5}}> <ProCard style={{margin: '0 auto', width: 1300, border: 1}}> <Form layout="inline" style={{padding: 3, flexDirection: 'column'}}> {/* 数据类型 */} <Form.Item label="数据类型" style={{marginBottom: 16}}> <Radio.Group defaultValue={''} onChange={handleDsTypeChange}> <Radio value="">不限</Radio> <Radio value="原始数据">原始数据</Radio> <Radio value="清洗后数据">清洗后数据</Radio> </Radio.Group> </Form.Item> {/* 是否认证 */} <Form.Item label="是否认证" style={{marginBottom: 16}}> <Radio.Group defaultValue={''} onChange={handleIsConfirmChange}> <Radio value="">不限</Radio> <Radio value="是">是</Radio> <Radio value="否">否</Radio> </Radio.Group> </Form.Item> </Form> </ProCard> <Row gutter={5} style={{marginTop: 5}}> <Col span={5}> <ProCard title="各领域树状结构"> <Tree showLine treeData={treeData} // @ts-ignore onSelect={onSelect} expandedKeys={expandedKeys} onExpand={onExpand} /> </ProCard> </Col> <Col span={19}> <ProCard title="数据资产列表"> <div> {isEmpty ? ( <div style={{ textAlign: 'center', padding: '50px 20px', color: '#999', fontSize: '16px', }}> 提示您搜索的关键词暂无相关数据资产 </div> ) : ( <List dataSource={assetsData} renderItem={(item) => ( <List.Item style={{marginBottom: -5}} key={item.id}> <Card style={{width: '100%', padding: 10}} bodyStyle={{padding: 5}}> <Title level={4}> <a href="#">{highlightKeyword(item.dsName, keyword)}</a>    {item.isConfirm === 'true' ? ( <Tag color="red" key={item.id}> 数据已确认 </Tag> ) : null} {item.tags.split(',').map((tag, index) => ( <Tag color="blue" key={index}> {highlightKeyword(tag, keyword)} </Tag> ))} </Title> <Text type="secondary">{highlightKeyword(item.dsTableName, keyword)}</Text> <Paragraph>{highlightKeyword(item.dsMemo, keyword)}</Paragraph> <Space direction="vertical" size="small"> <Text> 领域:<Text strong>{highlightKeyword(item.areaName, keyword)}</Text>     系统:<Text strong>{highlightKeyword(item.sysName, keyword)}</Text>     对象:<Text strong>{highlightKeyword(item.bussinessObjName, keyword)}</Text>     流程:<Text strong>{highlightKeyword(item.processPointName, keyword)}</Text> </Text> {/* 如果有样例文件则显示 */} {item.demoFileName && item.demoFileName !== '' ? ( <Text> 样例数据:{' '} <a href="#">{highlightKeyword(item.demoFileName, keyword)}</a>       <span onClick={() => handlePreview(item.demoOssFilePath)} style={{color: 'blue', cursor: 'pointer', marginRight: 10}} > 预览 </span>     <span> <a href={item.demoOssFilePath}>下载</a> </span> </Text> ) : null} </Space> </Card> </List.Item> )} /> )} <CustomPagination current={pageNum} total={totalItems} pageSize={10} onPageChange={handlePageChange} /> </div> </ProCard> </Col> </Row> </PageContainer> ); } export default SearchResultList; 以上代码 在按系统 、按对象、按流程 节点后面分别加一个超链接,链接到系统列表页、对象列表页、流程列表页
08-29
<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('123456789')"/> <th:block th:include="include :: datetimepicker-css"/> <!-- <th:block th:include="include :: datetimepicker-css"/>--> <th:block th:include="include :: bootstrap-fileinput-css"/> </head> <style> </style> <body> <form id="form-add" class="form-horizontal"> <div class="row"> <div class="col-sm-12"> <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button> <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i> </button> <div class="col-sm-12 select-table table-striped"> <table id="bootstrap-table"></table> </div> </div> </div> <div class="row"> <div class="col-sm-offset-5 col-sm-10"> <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存 </button>  <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button> </div> </div> </form> <!--style="opacity: 0;position: absolute;z-index: -1;"--> <!--<div>--> <!-- <div class='file-loading'>--> <!-- <input class='form-control file-upload' name='file' type='file' id="filex">--> <!-- </div>--> <!--</div>--> <th:block th:include="include :: footer"/> <th:block th:include="include :: echarts-js"/> <th:block th:include="include :: datetimepicker-js"/> <th:block th:include="include :: bootstrap-fileinput-js"/> <script th:inline="javascript"> $(function () { // 初始化数据, 可以由后台传过来 var data = [ { id: "100", name: "商品名称", weight: "100", price: "12.5", date: "2021-02-01", upload: "", type: "1", }, { id: "101", name: "商品名称2", weight: "50", price: "10.8", date: "2021-02-01", upload: "", type: "0", }]; var options = { data: data, pagination: false, showSearch: false, showRefresh: false, showToggle: false, showColumns: false, sidePagination: "client", columns: [{ checkbox: true }, { field: 'index', align: 'center', title: "序号", formatter: function (value, row, index) { var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index)); var columnId = $.common.sprintf("<input type='hidden' name='goods[%s].id' value='%s'>", index, row.id); return columnIndex + $.table.serialNumber(index) + columnId; // return $.table.serialNumber(index) + columnId; } }, { field: 'name', align: 'center', title: '商品名称', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].name' value='%s' >", index, value); return html; } }, { field: 'weight', align: 'center', title: '商品重量', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].weight' value='%s' >", index, value); return html; } }, { field: 'date', align: 'center', title: '商品日期', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].date' value='%s' >", index, value); return html; } }, { field: 'price', align: 'center', title: '商品价格', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].price' value='%s' >", index, value); return html; } }, { field: 'type', align: 'center', title: '商品种类', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].type' value='%s' >", index, value); return html; } }, { field: 'upload', align: 'center', title: '上传', formatter: function (value, row, index) { // var upload = $.common.sprintf("<input class='file-upload' id='goods[%s].upload' name='file' type='file'>", index); var html = $.common.sprintf("<input type='text' name='goods[%s].upload' value='%s' >", index, row.upload); var button = $.common.sprintf("<input type='button' onclick='uploaddata(%s)' value='上传' class='btn btn-primary'></input>", index); return html + button; } }, { title: '操作', align: 'center', formatter: function (value, row, index) { var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index); return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>'; } }] }; $.table.init(options); }); function addRow() { var count = $("#" + table.options.id).bootstrapTable('getData').length; var row = { index: $.table.serialNumber(count), name: "", weight: "", price: "", date: "", type: "", } sub.addRow(row); }; /* 主子表-提交 */ function submitHandler(index, layero) { var data = $("#form-add").serializeArray(); alert(JSON.stringify(data)) $.operate.saveModal("", data); } $(".file-upload").fileinput({ uploadUrl: ctx + 'common/upload', maxFileCount: 1, autoReplace: true, showPreview: false }).on('fileuploaded', function (event, data, previewId, index) { $("input[name='" + event.currentTarget.id + "']").val(data.response.url) }).on('fileremoved', function (event, id, index) { $("input[name='" + event.currentTarget.id + "']").val('') }) function uploaddata(data) { var url = ctx + "system/COMBINE/one7?index=" + data; // $.modal.open('onetest', url) $.modal.openOptions({ title: '上传文件', url: url, btn: 0 }) } $(document).ready(function () { // 接收子页面传来的消息 window.addEventListener("message", function (event) { if (event.data && event.data.type === "uploadComplete") { var url = event.data.value; console.log(url); // 设置对应商品的上传字段 $("input[name='goods[" + event.data.index + "].upload']").val(url); } }); }); </script> </body> </html> <!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('123456789')"/> <th:block th:include="include :: datetimepicker-css"/> <!-- <th:block th:include="include :: datetimepicker-css"/>--> <th:block th:include="include :: bootstrap-fileinput-css"/> </head> <style> </style> <body> <div> <div> <input type="text" name="filex" id="inputfile"> <div class='file-loading'> <input class='form-control file-upload' name='file' type='file' id="filex"> </div> </div> <div> <button onclick="chuli()">确定</button> </div> </div> <th:block th:include="include :: footer"/> <th:block th:include="include :: echarts-js"/> <th:block th:include="include :: datetimepicker-js"/> <th:block th:include="include :: bootstrap-fileinput-js"/> <script th:inline="javascript"> $(".file-upload").fileinput({ uploadUrl: ctx + 'common/upload', maxFileCount: 1, autoReplace: true, showPreview: false }).on('fileuploaded', function (event, data, previewId, index) { $("input[name='" + event.currentTarget.id + "']").val(data.response.url) }).on('fileremoved', function (event, id, index) { $("input[name='" + event.currentTarget.id + "']").val('') }) // var url = ctx + "system/COMBINE/one7?index=" + index; // 获取父页面传入的 index(例如通过URL参数) const urlParams = new URLSearchParams(window.location.search); // console.log(urlParams); const rowIndex = urlParams.get('index'); // URL参数中传入当前行索引 console.log(rowIndex); function chuli() { var url = $("#inputfile").val(); if (!url) { alert("请先上传文件"); return; } // 使用 postMessage 向父页面发送消息 window.parent.postMessage({ type: 'uploadComplete', value: url, index: rowIndex // 传回当前行索引 }, '*'); $.modal.close(); } </script> </body> </html> 这是我的两段代码,我这个使用的是ruoyi,bootstrap版本的,我使用 // 使用 postMessage 向父页面发送消息 window.parent.postMessage({ type: 'uploadComplete', value: url, index: rowIndex // 传回当前行索引 }, '*'); 和$(document).ready(function () { // 接收子页面传来的消息 window.addEventListener("message", function (event) { if (event.data && event.data.type === "uploadComplete") { var url = event.data.value; console.log(url); // 设置对应商品的上传字段 $("input[name='goods[" + event.data.index + "].upload']").val(url); } }); }); 没有用
最新发布
09-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值