fastadmin框架前台常用语句
发布时间
阅读量:
阅读量
引入外部js并调用
require(['spectrum'], function (spectrum) {
var col = $("#c-mcolor").val();
$("#c-mcolor").spectrum({
color: col,
preferredFormat: "hex",
showInput: true,
});
var gcol = $("#c-mbgcolor").val();
$("#c-mbgcolor").spectrum({
color: gcol,
preferredFormat: "hex",
showInput: true,
});
});
AI写代码
2.隐藏某字段的显示和隐藏通用搜索
//visible隐藏字段,operate隐藏通用搜索
{field: 'id', title: __('Id'),visible: false,operate: false},
AI写代码
3.通用搜索改为select搜索
js代码
//data是添加属性
{field: 'reptype', title: __('Reptype'),searchList: $.getJSON("ajax/reptype"),data:' id = "mm_city" '},
//或者直接写
{field: 'status', title: __('status'), searchList: {"0":__('待审核'),"1,2,3":__('已审')}},
AI写代码
ajax控制器中代码
public function reptype(){
$areaList = Db::name('report_type')->field('id,name')->select();
return json($areaList);
}
AI写代码
4.给某字段添加判断效果
{field: 'createtime', title: __('Createtime'), formatter:function(value,row,index){
if( 0 < value && value <= 3){
return '<b style = "color:red">' + value + '天</b>';
}else{
return value + "天" ;
}
}},
AI写代码
5.在操作中添加按钮
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [{
name: 'detail',
text: __('详情'),
title: function(row){return '名称:' + row.name },
icon: 'fa fa-list',
classname: 'btn btn-info btn-xs btn-detail btn-dialog',
url: 'personal_report/detail',
// hidden: function(row){
// if(row.name != '环境'){
// return true;
// }
// }
}], formatter: Table.api.formatter.operate}
AI写代码
6.在add页面添加点击事件
//查看图片
$(document).on("click", ".img-center", function (e) {
Layer.photos({
photos: {
"data": [{"src": e.target.src}]
},
anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
});
});
//提交数据
$(document).on("click", "#transfer", function (e) {
var id = e.target.dataset.id;
$.post(
"personal_report/condition",
{
id: id,
status: 1
},
function(data){
if(data){
layer.msg('提交成功!');
}
}
);
});
//
AI写代码
7.一个表的里的tab切换
// 初始化表格,原始是
table.bootstrapTable({
});
//改为
var tableOptions = ({
});
table.bootstrapTable(tableOptions);
//绑定TAB事件
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
// var options = table.bootstrapTable(tableOptions);
var typeStr = $(this).attr("href").replace('#', '');
var options = table.bootstrapTable('getOptions');
options.pageNumber = 1;
options.queryParams = function (params) {
// params.filter = JSON.stringify({type: typeStr});
params.filter = typeStr == 'all' ? '' : JSON.stringify({status: typeStr});
return params;
};
table.bootstrapTable('refresh', {});
return false;
});
AI写代码
index页面tab切换代码
<div class="panel panel-default panel-intro">
<!-- 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 -->
<div class="panel-heading">
{:build_heading(null,FALSE)}
<ul class="nav nav-tabs">
<li class="active"><a href="#all" data-toggle="tab" aria-expanded="true">{:__('All')}</a></li>
//sortList从控制器初始化时生成
//$this->view->assign("sortList", $this->model->getStatusList());
{foreach name="sortList" item="vo"}
<li><a href="#{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
</ul>
</div>
<!-- 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 -->
<div class="panel-body">
AI写代码
8.页面某终端过长时
{field: 'opinion', title: __('Opinion'), cellStyle: function () {return {css: {"max-width": "200px","overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}}},
//或者
{field: 'source', title: __('Source'),cellStyle: {css: {"max-width": "180px","white-space": "unset"}}},
AI写代码
9.自己写的单独页面需要用框架中的插件时需加入
{include file="common/meta" /}
{include file="common/script" /}
AI写代码
10.给页面某字段添加事件
{field: 'weigh', title: __('使用'), events: Controller.api.events.click, formatter: Controller.api.formatter.ip, operate: false},
//api里添加
api: {
bindevent: function () {
//tab切换时把当前tab值代入add/edit页面里的select上
$(document).on("change", "#c-sort", function () {
var tab = $('a[data-toggle="tab"][aria-expanded="true"]', parent.document).attr("href").replace('#', '');
$("#c-sort").find("option[value='"+tab+"']").attr("selected",true);
// $("#c-pid option[data-type='all']").prop("selected", true);
// $("#c-pid option").removeClass("hide");
// $("#c-pid option[data-type!='" + $(this).val() + "'][data-type!='all']").addClass("hide");
// $("#c-pid").data("selectpicker") && $("#c-pid").selectpicker("refresh");
});
Form.api.bindevent($("form[role=form]"));
},
events: {
click: {
'click .addssssss': function (e, value, row, index) {
e.stopPropagation();
e.preventDefault();
var table = $(this).closest('table');
var options = table.bootstrapTable('getOptions');
var ids = row[options.pk];
row = $.extend({}, row ? row : {}, {ids: ids});
var url = options.extend.flowmeter_url + "?id=" + row.id +"&flag=0";
Fast.api.open(Table.api.replaceurl(url, row, table), __('Add'), $(this).data() || {});
}
},
},
formatter: {
ip: function (value, row, index) {
return '<a class="label label-success addtabsit addssssss" title="' + __("使用") + '">' + __("使用") + '</a>';
//方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容
//return '<a class="label label-success addtabsit addssssss" title="' + __("Search") + '">' + __('追加') + '</a>';
}
}
}
AI写代码
11.jquery常用事件
//input输入事件
$('input#c-money').on('input propertychange', function(e){
});
//点击事件
$(document).on("click", ".img-center", function (e) {
});
//改变事件
$("select#c-xid").change(function(){
});
//
AI写代码
12.页面里用的循环和判断
{volist name="$row" id="vi" }
{$vi['name']}
{if $vi['isimage'] == 1}
111
{else/}
222
{/if}
{/volist}
{foreach name="fix" item="vo"}
{$vo['name']}
{/foreach}
AI写代码
13.页面里添加弹窗
//页面里的代码
<a href="javascript:;" class="btn btn-info btn-exchange active"><i class="fa fa-list"></i>{:__('Exchange')}</a>
//初始化配置中添加路径
exchange: 'integral/exchange',
//index中添加点击事件相应
$(document).on("click", ".btn-alter", function () {
var ids = Table.api.selectedids(table);
var url = $.fn.bootstrapTable.defaults.extend.userEdit_url;
if (url.indexOf("{ids}") !== -1) {
url = Table.api.replaceurl(url, {ids: ids.length > 0 ? ids.join(",") : 0}, table);
}
Fast.api.open(url, __('Alter'), $(this).data() || {});
});
//添加一个类似add的Controller
useredit: function () {
Form.api.bindevent($("form[role=form]"));
},
AI写代码
13.获取iframe中的的元素值
$("#ifmap").contents().find("#clmap").click(function(){
var test = $(window.frames["ifmap"].document).contents().find("#mapname").val();
var tlng = $(window.frames["ifmap"].document).contents().find("#maplng").val();
$("#address").val(test);
$("#addlng").val(tlng);
});
AI写代码
全部评论 (0)
还没有任何评论哟~
